Assembly
Bitwise Operations (AND/OR/XOR/NOT)
Bitwise operations work on individual bits, ignoring signed/unsigned concepts.
Core Operations
AND - both bits must be 1:
asm
mov al, 0b11001100
and al, 0b11110000 ; Result: 0b11000000OR - at least one bit must be 1:
asm
mov al, 0b11001100
or al, 0b00110011 ; Result: 0b11111111XOR - bits must be different:
asm
mov al, 0b11001100
xor al, 0b11110000 ; Result: 0b00111100NOT - flip all bits:
asm
mov al, 0b11001100
not al ; Result: 0b00110011Useful Examples
asm
# Zeroing a register (preferred method):
xor eax, eax ; 2 bytes: 31 C0
mov eax, 0 ; 5 bytes: B8 00 00 00 00
# Changing permissions
mov eax, 0b11100101 ; 101 r-x
or eax, 0b00000010 ; 111 rwx
and eax, 0b11111011 ; 011 -wx
xor eax, 0b00000010 ; 001 r--
and eax, 0b00000000 ; 000 ---