python - bitwise NOR Gate - what does & mean? -


this question has answer here:

i'm trying understand code answer received yesterday:

2nd: how make bitwise nor gate
1st: how bitwise nor gate in python (editing python maths work me)

a=0b01100001 b=0b01100010  bin((a ^ 0b11111111) & (b ^ 0b11111111)) 

i understand except:

the & between 2 values

and ^ 11111111 ( know 0b base 2)

can please explain these?

how nor works?

the expression x nor y can broken using and, or, , not:

x nor y == not(x or y) == not(x) , not(y) 

so, given values:

a=0b01100001 b=0b01100010 

a nor b not(a) , not(b). think how not(a)? need flip bits. way flip bits? xor(^). how?

0 ^ 1 == 1 1 ^ 1 == 0 

so, taking xor of bit 1 flip bit. i.e. not(somebit) == xor somebit. so, in case, take xor of each bits in a , b 1 not:

   01100001 ^  11111111 ------------    10011110 

that is, xor 11111111. note number of 1's same number of bits in a.

putting together:

not(a) = ^ 0b11111111 not(b) = b ^ 0b11111111 

now, got nots of a , b, let's and. so, what's way and? bitwise &.

that's pretty simple:

not(a) , not(b) == (a ^ 0b11111111) & (b ^ 0b11111111) 

Comments

Post a Comment

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -