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.

A213064 Bitwise AND of 2n with the one's-complement of n.

This page as a plain text file.
%I A213064 #41 Aug 17 2025 12:42:09
%S A213064 0,2,4,4,8,10,8,8,16,18,20,20,16,18,16,16,32,34,36,36,40,42,40,40,32,
%T A213064 34,36,36,32,34,32,32,64,66,68,68,72,74,72,72,80,82,84,84,80,82,80,80,
%U A213064 64,66,68,68,72,74,72,72,64,66,68,68,64,66,64,64,128,130,132
%N A213064 Bitwise AND of 2n with the one's-complement of n.
%C A213064 In two's-complement binary arithmetic, -n is ~(n - 1). As such, this could be written instead as a(n) = 2n AND -(n + 1).  Further, because the least significant bits are never matched both of the operands to the AND, the negative form of n can be used rather than the one's-complement, i.e. a(n) = 2n AND -n.
%C A213064 a(n) has a 1-bit immediately above each run of 1's in n, and everywhere else 0's.  Or equivalently, each 01 bit pair in n becomes 10 in a(n) and everywhere else 0's.  The most significant 1-bit of n has a 0 above it for this purpose, so is an 01 bit pair. - _Kevin Ryde_, Jun 04 2020
%H A213064 Juli Mallett, <a href="/A213064/b213064.txt">Table of n, a(n) for n = 0..9999</a>
%H A213064 <a href="/index/Bi#binary">Index entries for sequences related to binary expansion of n</a>
%F A213064 a(n) = 2n AND ~n
%F A213064 a(n) = 2*A292272(n). - _Kevin Ryde_, Jun 04 2020
%e A213064 For n = 31, 2n is 62, which in binary is 111110, as multiplication by two is the same as shifting the bits of 31 (11111) to the left by one. As the number is one less than a power of two, all of its least significant bits are set. Before the shift, the most significant bit has a value of 16. After the shift, the most significant bit has a value of 32.
%e A213064 The ~n has all bits set but the five least significant, the highest bit set being the power of two above n: .....111111111100000. When these two values are ANDed together, only the 6th bit, that with the value of 32, is common to them, and the result is 32.
%e A213064 From _Kevin Ryde_, Jun 04 2020: (Start)
%e A213064      n = 1831 = binary  11100100111
%e A213064   a(n) = 2120 = binary 100001001000   1-bit above each run
%e A213064 (End)
%t A213064 Table[BitAnd[2n, -n], {n, 0, 66}] (* _Alonso del Arte_, Jun 04 2012 *)
%o A213064 (C) int a(int n) { return ((n + n) & ~n); }
%o A213064 (R) # with bitops
%o A213064 bitAnd(2 * n, bitFlip(n))
%o A213064 (PARI) a(n) = bitnegimply(n<<1,n); \\ _Kevin Ryde_, Jun 04 2020
%o A213064 (Python)
%o A213064 def A213064(n): return n<<1&~n # _Chai Wah Wu_, Jun 29 2022
%Y A213064 Cf. A048724 (with XOR).
%K A213064 nonn,base,easy
%O A213064 0,2
%A A213064 _Juli Mallett_, Jun 04 2012