A334045 Bitwise NOR of binary representation of n and n-1.
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, 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, 4, 4, 0, 2, 0, 0, 0, 62, 60, 60, 56, 58, 56, 56, 48, 54, 52, 52
Offset: 1
Examples
a(11) = 11 NOR 10 = bin 1011 NOR 1010 = bin 100 = 4.
Links
- Wikipedia, Bitwise operation
Programs
-
Maple
a:= n-> Bits[Nor](n, n-1): seq(a(n), n=1..100); # Alois P. Heinz, Apr 13 2020
-
PARI
a(n) = my(x=bitor(n-1, n)); bitneg(x, #binary(x)); \\ Michel Marcus, Apr 13 2020
-
Python
def norbitwise(n): a = str(bin(n))[2:] b = str(bin(n-1))[2:] if len(b) < len(a): b = '0' + b c = '' for i in range(len(a)): if a[i] == b[i] and a[i] == '0': c += '1' else: c += '0' return int(c,2)
-
Python
def A334045(n): m = n|(n-1) return 2**(len(bin(m))-2)-1-m # Chai Wah Wu, Apr 13 2020
Comments