login
The OEIS Foundation is supported by donations from users of the OEIS and by a grant from the Simons Foundation.

 

Logo


Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A274009 1's distance from a number in its binary expansion. 0
1, 0, 2, 1, 2, 1, 3, 2, 2, 1, 3, 2, 3, 2, 4, 3, 2, 1, 3, 2, 3, 2, 4, 3, 3, 2, 4, 3, 4, 3, 5, 4, 2, 1, 3, 2, 3, 2, 4, 3, 3, 2, 4, 3, 4, 3, 5, 4, 3, 2, 4, 3, 4, 3, 5, 4, 4, 3, 5, 4, 5, 4, 6, 5, 2, 1, 3, 2, 3, 2, 4, 3, 3, 2, 4, 3, 4, 3, 5, 4, 3, 2, 4, 3, 4, 3, 5, 4, 4, 3 (list; graph; refs; listen; history; text; internal format)
OFFSET

0,3

COMMENTS

To generate the value for n, write out n's decimal expansion.  Then, write out 1's decimal expansion (0000000000....001).  Compute how many times you need to change 0 to a 1 or a 1 to a 0 in order to switch from one number to the other.

The value for 2^x is always 2.  The value for 2^x +1 is always 1.  The value for 2^x -1 is always x-1 when x > 0. To get to 2^x, you need to drop the 1 at the beginning and add the 1 in the 2^x place value.

For 2^x + 1, you need to add the 1 in the 2^n place value, but you keep the 1 in the 1s place value.  Thus you are only adding or getting rid of 1 digit.

For 2^x -1, it will have x digits, and all of them will be 1's.  You already have 1 in the 1's place value, so there are n-1 digits left over.

LINKS

Table of n, a(n) for n=0..89.

FORMULA

a(n) = A000120(n) + (-1)^n. - Michel Marcus, Jul 14 2016

MATHEMATICA

Table[If[OddQ@ n, # - 1, # + 1] &@ DigitCount[n, 2, 1], {n, 0, 120}] (* Michael De Vlieger, Jul 13 2016 *)

PROG

(PARI) a(n) = hammingweight(n) + (-1)^n; \\ Michel Marcus, Jul 14 2016

CROSSREFS

Cf. A000120.

Sequence in context: A331600 A039637 A194548 * A069157 A294894 A076526

Adjacent sequences:  A274006 A274007 A274008 * A274010 A274011 A274012

KEYWORD

nonn,base

AUTHOR

William K. Grannis, Jun 06 2016

EXTENSIONS

More terms from Michel Marcus, Jul 13 2016

STATUS

approved

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

License Agreements, Terms of Use, Privacy Policy. .

Last modified July 28 19:33 EDT 2021. Contains 346335 sequences. (Running on oeis4.)