A160638 Bit-reversed 8-bit binary numbers.
0, 128, 64, 192, 32, 160, 96, 224, 16, 144, 80, 208, 48, 176, 112, 240, 8, 136, 72, 200, 40, 168, 104, 232, 24, 152, 88, 216, 56, 184, 120, 248, 4, 132, 68, 196, 36, 164, 100, 228, 20, 148, 84, 212, 52, 180, 116, 244, 12, 140, 76, 204, 44, 172, 108, 236, 28, 156
Offset: 0
Examples
n = 1 = 00000001 binary, so a(1) = 10000000 binary = 128. n = 29 = 00011101 binary, so a(29) = 10111000 binary = 184.
References
- Henry S. Warren, Hacker's Delight, Addison-Wesley, 2002, pages 101-106.
Links
- Russ Cox, Table of n, a(n) for n = 0 .. 255 (full sequence)
- Sean Anderson, Bit Twiddling Hacks
- Michael Beeler, R. William Gosper and Richard C. Schroeppel, HAKMEM (MIT AI Memo 239, Feb. 29, 1972), Item 167.
Crossrefs
Cf. A217589.
Programs
-
C
int a = 0; for(int i=0; i<8; i++) if(n & (1<
-
Haskell
import Data.Bits (testBit, setBit) import Data.Word (Word8) a160638 :: Word8 -> Word8 a160638 n = rev 0 0 where rev 8 y = y rev i y = rev (i + 1) (if testBit n i then setBit y (7 - i) else y) -- Reinhard Zumkeller, Jan 12 2013
-
Maple
a:= n-> Bits[Join](ListTools[Reverse](Bits[Split](n, bits=8))): seq(a(n), n=0..255); # Alois P. Heinz, Nov 28 2024
-
Mathematica
a[n_] := FromDigits[PadLeft[IntegerDigits[n, 2], 8] // Reverse, 2]; Table[a[n], {n, 0, 255}] (* Jean-François Alcover, Dec 26 2015 *) IntegerReverse[Range[0, 255], 2, 8] (* Paolo Xausa, Nov 28 2024 *)
-
PARI
A160638(n)=binary(n+256)*vector(9,n,2^n)~\4 \\ M. F. Hasler, Oct 07 2012
-
PARI
A160638(n)=sum(i=0,7,bittest(n,7-i)<M. F. Hasler, Oct 07 2012
-
Python
def a(n): return int(bin(n)[2:].zfill(8)[::-1], 2) print([a(n) for n in range(256)]) # Michael S. Branicky, Jul 13 2022
Formula
a(n) = floor(A030101(n+256)/2). - Reinhard Zumkeller, Jan 12 2013
Comments