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.

A334045 Bitwise NOR of binary representation of n and n-1.

This page as a plain text file.
%I A334045 #34 Jan 14 2021 02:23:20
%S A334045 0,0,0,0,2,0,0,0,6,4,4,0,2,0,0,0,14,12,12,8,10,8,8,0,6,4,4,0,2,0,0,0,
%T A334045 30,28,28,24,26,24,24,16,22,20,20,16,18,16,16,0,14,12,12,8,10,8,8,0,6,
%U A334045 4,4,0,2,0,0,0,62,60,60,56,58,56,56,48,54,52,52
%N A334045 Bitwise NOR of binary representation of n and n-1.
%C A334045 All terms are even.
%C A334045 a(1) = 0, a(2) = 0, and a(2^n + 1) = 2^n - 2 for n > 0. Are there any other cases where n - a(n) < 4? - _Charles R Greathouse IV_, Apr 13 2020
%C A334045 The answer to the above question is no. Write n as n = (2m+1)*k, i.e. k = A006519(n) is the highest power of 2 dividing n. If m = 0, a(n) = 0 and n - a(n) = n. If m > 0, then a(n) = 2v*k, where v is the 1's complement of m. Thus n-a(n) = (2(m-v)+1)*k. Since m in binary has a leading 1, m - v >= 1 and thus n - a(n) >= 3 with n - a(n) = 3 when n > 2, k = 1 and m - v = 1, i.e. m is a power of 2 and n is of the form 2^r + 1. - _Chai Wah Wu_, Apr 13 2020
%H A334045 Wikipedia, <a href="https://en.wikipedia.org/wiki/Bitwise operation">Bitwise operation</a>
%e A334045 a(11) = 11 NOR 10 = bin 1011 NOR 1010 = bin 100 = 4.
%p A334045 a:= n-> Bits[Nor](n, n-1):
%p A334045 seq(a(n), n=1..100);  # _Alois P. Heinz_, Apr 13 2020
%o A334045 (Python)
%o A334045 def norbitwise(n):
%o A334045     a = str(bin(n))[2:]
%o A334045     b = str(bin(n-1))[2:]
%o A334045     if len(b) < len(a):
%o A334045         b = '0' + b
%o A334045     c = ''
%o A334045     for i in range(len(a)):
%o A334045         if a[i] == b[i] and a[i] == '0':
%o A334045             c += '1'
%o A334045         else:
%o A334045             c += '0'
%o A334045     return int(c,2)
%o A334045 (Python)
%o A334045 def A334045(n):
%o A334045     m = n|(n-1)
%o A334045     return 2**(len(bin(m))-2)-1-m # _Chai Wah Wu_, Apr 13 2020
%o A334045 (PARI) a(n) = my(x=bitor(n-1, n)); bitneg(x, #binary(x)); \\ _Michel Marcus_, Apr 13 2020
%Y A334045 Cf. A038712 (n XOR n-1), A086799 (n OR n-1), A129760 (n AND n-1).
%K A334045 easy,base,nonn
%O A334045 1,5
%A A334045 _Christoph Schreier_, Apr 13 2020