login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A145037 Number of 1's minus number of 0's in the binary representation of n. 17
0, 1, 0, 2, -1, 1, 1, 3, -2, 0, 0, 2, 0, 2, 2, 4, -3, -1, -1, 1, -1, 1, 1, 3, -1, 1, 1, 3, 1, 3, 3, 5, -4, -2, -2, 0, -2, 0, 0, 2, -2, 0, 0, 2, 0, 2, 2, 4, -2, 0, 0, 2, 0, 2, 2, 4, 0, 2, 2, 4, 2, 4, 4, 6, -5, -3, -3, -1, -3, -1, -1, 1, -3, -1, -1, 1, -1, 1, 1, 3, -3, -1, -1, 1, -1, 1, 1, 3, -1, 1, 1 (list; graph; refs; listen; history; text; internal format)
OFFSET
0,4
COMMENTS
Column 2 of A144912 (which begins at n = 2).
Zeros in that column correspond to A031443.
LINKS
FORMULA
a(n) = -A037861(n) for n >= 1.
a(n) = Sum_{i=1..k} (2*b[i] - 1) where b is the binary expansion of n and k is the number of bits in this binary expansion. - Michel Marcus, Jun 28 2021
From Aayush Soni Feb 12 2022: (Start)
Upper bound: a(n) <= floor(log_2(n+1)).
Lower bound: For n > 0, a(n) >= 1 - floor(log_2(n)).
If n is even, a(2^n) to a(2^(n+1)-1) inclusive are all odd and vice versa. (End)
EXAMPLE
From Michel Marcus, Feb 12 2022: (Start)
Viewed as an irregular triangle:
0;
1;
0, 2;
-1, 1, 1, 3;
-2, 0, 0, 2, 0, 2, 2, 4;
-3, -1, -1, 1, -1, 1, 1, 3, -1, 1, 1, 3, 1, 3, 3, 5;
... (End)
MAPLE
a:= n-> add(2*i-1, i=Bits[Split](n)):
seq(a(n), n=0..90); # Alois P. Heinz, Jan 18 2022
MATHEMATICA
Join[{0}, Table[Count[#, 1] - Count[#, 0] &[IntegerDigits[n, 2]], {n, 1, 90}]] (* Robert P. P. McKone, Feb 12 2022 *)
PROG
(Haskell)
a145037 0 = 0
a145037 n = a145037 n' + 2*m - 1 where (n', m) = divMod n 2
-- Reinhard Zumkeller, Jun 16 2011
(PARI) A145037(n)=hammingweight(n)*2-logint(n<<1+!n, 2) \\ M. F. Hasler, Mar 08 2018
(Python)
result = [0]
for n in range (1, 2**14 + 1):
result.append(bin(n)[2:].count("1") - bin(n)[2:].count("0"))
print(result[0:129]) # Karl-Heinz Hofmann, Jan 18 2022
(C#)
int A145037(int n) {
int result = 0;
while(n > 0) {
result += 2 * (n % 2) - 1;
n /= 2;
}
return result;
} \\ Frank Hollstein, Dec 08 2022
CROSSREFS
Cf. A037861 (negated), A031443 (indices of 0's), A144912, A000120.
Cf. A269735 (first differences), A268289 (partial sums).
Column k=1 of A360099.
Sequence in context: A077254 A074761 A037861 * A267115 A328919 A277647
KEYWORD
sign,base,easy
AUTHOR
Reikku Kulon, Sep 30 2008
EXTENSIONS
Renamed (using a Mar 08 2018 comment from M. F. Hasler) and edited by Jon E. Schoenfield, Jun 29 2021
STATUS
approved

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified April 24 11:49 EDT 2024. Contains 371936 sequences. (Running on oeis4.)