cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A160638 Bit-reversed 8-bit binary numbers.

This page as a plain text file.
%I A160638 #42 Nov 28 2024 11:39:41
%S A160638 0,128,64,192,32,160,96,224,16,144,80,208,48,176,112,240,8,136,72,200,
%T A160638 40,168,104,232,24,152,88,216,56,184,120,248,4,132,68,196,36,164,100,
%U A160638 228,20,148,84,212,52,180,116,244,12,140,76,204,44,172,108,236,28,156
%N A160638 Bit-reversed 8-bit binary numbers.
%C A160638 This sequence is found in computer programs that need to reverse the bits in a byte, typically during data compression or other bit-level encoding. a(n) is its own inverse: a(a(n)) = n.
%C A160638 A permutation of the integers 0-255. - _Jon Perry_, Oct 06 2012
%C A160638 a(n) is even for 0 <= n< 128 and odd for n <= 128 < 256. - _Jon Perry_, Oct 06 2012
%C A160638 a(m) + a(n) = a(m+n) when the binary representations of m and n have no bits in common. - _Jon Perry_, Oct 06 2012
%D A160638 Henry S. Warren, Hacker's Delight, Addison-Wesley, 2002, pages 101-106.
%H A160638 Russ Cox, <a href="/A160638/b160638.txt">Table of n, a(n) for n = 0 .. 255</a> (full sequence)
%H A160638 Sean Anderson, <a href="http://graphics.stanford.edu/~seander/bithacks.html#BitReverseObvious">Bit Twiddling Hacks</a>
%H A160638 Michael Beeler, R. William Gosper and Richard C. Schroeppel, <a href="http://www.inwap.com/pdp10/hbaker/hakmem/hacks.html#item167">HAKMEM (MIT AI Memo 239, Feb. 29, 1972)</a>, Item 167.
%F A160638 a(n) = floor(A030101(n+256)/2). - _Reinhard Zumkeller_, Jan 12 2013
%e A160638 n = 1 = 00000001 binary, so a(1) = 10000000 binary = 128.
%e A160638 n = 29 = 00011101 binary, so a(29) = 10111000 binary = 184.
%p A160638 a:= n-> Bits[Join](ListTools[Reverse](Bits[Split](n, bits=8))):
%p A160638 seq(a(n), n=0..255);  # _Alois P. Heinz_, Nov 28 2024
%t A160638 a[n_] := FromDigits[PadLeft[IntegerDigits[n, 2], 8] // Reverse, 2]; Table[a[n], {n, 0, 255}] (* _Jean-François Alcover_, Dec 26 2015 *)
%t A160638 IntegerReverse[Range[0, 255], 2, 8] (* _Paolo Xausa_, Nov 28 2024 *)
%o A160638 (C) int a = 0; for(int i=0; i<8; i++) if(n & (1<<i)) a |= 1<<(7 - i);
%o A160638 (PARI) A160638(n)=binary(n+256)*vector(9,n,2^n)~\4  \\ _M. F. Hasler_, Oct 07 2012
%o A160638 (PARI) A160638(n)=sum(i=0,7,bittest(n,7-i)<<i)  \\ _M. F. Hasler_, Oct 07 2012
%o A160638 (Haskell)
%o A160638 import Data.Bits (testBit, setBit)
%o A160638 import Data.Word (Word8)
%o A160638 a160638 :: Word8 -> Word8
%o A160638 a160638 n = rev 0 0 where
%o A160638    rev 8 y = y
%o A160638    rev i y = rev (i + 1) (if testBit n i then setBit y (7 - i) else y)
%o A160638 -- _Reinhard Zumkeller_, Jan 12 2013
%o A160638 (Python)
%o A160638 def a(n): return int(bin(n)[2:].zfill(8)[::-1], 2)
%o A160638 print([a(n) for n in range(256)]) # _Michael S. Branicky_, Jul 13 2022
%Y A160638 Cf. A217589.
%K A160638 base,easy,fini,full,nonn,nice
%O A160638 0,2
%A A160638 _Russ Cox_, May 21 2009