This page determine the bitwise operations for AND, NAND, OR, NOR and X-OR:
Bitwise operations |
Sample run
The following is a sample run:
Decimal form: 00110101 Decimal form: 00110111 Result: -------------------- Bitwise AND: 00110101 Bitwise NAND: 11001010 Bitwise OR: 00110111 Bitwise NOR: 11001000 Bitwise XOR: 00000010
Code
The following is the Python code:
import sys val1="00110101" val2="00110111" if (len(sys.argv)>1): val1=sys.argv[1] if (len(sys.argv)>2): val2=sys.argv[2] def nor(p, q): return ~ (p | q) & 0xff; def nand(p, q): return ~(p & q) & 0xff; dec1=int(val1,2) dec2=int(val2,2) print ("Decimal form:\t",bin(dec1)[2:10].rjust(8,'0')) print ("Decimal form:\t",bin(dec2)[2:10].rjust(8,'0')) print ("\nResult:") print ("--------------------") print ("Bitwise AND:\t",bin(dec1 & dec2)[2:10].rjust(8,'0')) print ("Bitwise NAND:\t",bin(nand(dec1,dec2))[2:10].rjust(8,'0')) print ("Bitwise OR:\t",bin(dec1 | dec2)[2:10].rjust(8,'0')) print ("Bitwise NOR:\t",bin(nor(dec1,dec2))[2:10].rjust(8,'0')) print ("Bitwise XOR:\t",bin(dec1 ^ dec2)[2:10].rjust(8,'0'))
AND (Z=A.B)
A B Z ----- 0 0 0 0 1 0 1 0 0 1 1 1
OR (Z=A+B)
A B Z ----- 0 0 0 0 1 1 1 0 1 1 1 1
NAND (Z=A.B)
A B Z ----- 0 0 1 0 1 1 1 0 1 1 1 0
NOR (Z=A+B)
A B Z ----- 0 0 1 0 1 0 1 0 0 1 1 0
X-OR (Z=A⊕B)
A B Z ----- 0 0 0 0 1 1 1 0 1 1 1 0
The electronic gates used are: