OFFSET
0,6
COMMENTS
A literal interpretation of the binary numbers.
Sum of the number of digits to the left (exclusive) of each 1 in the binary expansion of n. - Gus Wiseman, Jan 09 2023
LINKS
Rémy Sigrist, Table of n, a(n) for n = 0..8192
FORMULA
EXAMPLE
For n=13 we have 1101, so we add 0+1+3=4, getting a(13)=4.
MAPLE
f:=proc(n) local t1, m, i;
t1:=convert(n, base, 2);
m:=nops(t1)-1;
add((m-i)*t1[i+1], i=0..m);
end; # N. J. A. Sloane, Nov 08 2013
MATHEMATICA
Table[Total[Join@@Position[IntegerDigits[n, 2], 1]-1], {n, 0, 100}] (* Gus Wiseman, Jan 09 2023 *)
PROG
(JavaScript)
for (i=0; i<100; i++) {
s=i.toString(2);
o=0;
sl=s.length;
for (j=0; j<sl; j++) if (s.charAt(j)==1) o+=j;
document.write(o+", ");
}
(PARI) a(n) = { my (b=binary(n)); sum(k=1, #b, b[k]*(k-1)) } \\ Rémy Sigrist, Jun 25 2021
(Python)
def A230204(n): return sum(i for i, j in enumerate(bin(n)[2:]) if j=='1') # Chai Wah Wu, Jan 09 2023
KEYWORD
nonn,base
AUTHOR
Jon Perry, Nov 05 2013
EXTENSIONS
Edited by N. J. A. Sloane, Nov 08 2013
Name edited by Gus Wiseman, Jan 09 2023
STATUS
approved