|
Search: id:A065620
|
|
|
| A065620 |
|
Reversing binary value of n. Convert sum of powers of 2 in binary representation of n to alternating sum. |
|
+0 3
|
|
| 1, 2, -1, 4, -3, -2, 3, 8, -7, -6, 7, -4, 5, 6, -5, 16, -15, -14, 15, -12, 13, 14, -13, -8, 9, 10, -9, 12, -11, -10, 11, 32, -31, -30, 31, -28, 29, 30, -29, -24, 25, 26, -25, 28, -27, -26, 27, -16, 17, 18, -17, 20, -19, -18, 19, 24, -23, -22, 23, -20, 21, 22, -21, 64, -63, -62, 63, -60, 61, 62, -61, -56
(list; graph; listen)
|
|
|
OFFSET
|
1,2
|
|
|
COMMENT
|
a(0)=0. The alternation is applied only to the nonzero bits and does not depend on the exponent of two. All integers have a unique reversing binary representation (see cited exercise for proof).
|
|
REFERENCES
|
D. E. Knuth, The Art of Computer Programming. Addison-Wesley, Reading, MA, 1969, Vol. 2, p. 178, (exercise 4.1. Nr. 27)
|
|
FORMULA
|
a(n) = if n<2 then n else b+2*(1-2*b)*a((n-b)/2) where b is the least significant bit in n.
a(2n) = 2a(n), a(2n+1) = -a(n) + 1.
|
|
EXAMPLE
|
11 = 1 + 2 + 8 -> 1 - 2 + 8 = 7 = a(11)
|
|
CROSSREFS
|
A065621, A048724
Adjacent sequences: A065617 A065618 A065619 this_sequence A065621 A065622 A065623
Sequence in context: A023141 A072650 A082497 this_sequence A104895 A103122 A087850
|
|
KEYWORD
|
base,easy,sign
|
|
AUTHOR
|
Marc LeBrun (mlb(AT)well.com), Nov 07 2001
|
|
|
Search completed in 0.002 seconds
|