Bit-wise Operations(1.4.1 i) Flashcards
What is a bit-wise operation?
any operation that is carried out one bit at a time
adding and subtracting and must be carried out from right to left
can do logical operations like AND OR XOR and NOT and can work in either direction
Bit-wise operation NOT
simplest bit-wise operation
simply flip every bit
What is a mask?
used in bit-wise operations to either reveal important information and/or hide unimportant information
How is a mask applied?
AND and OR operations
AND masks
0 hides unneeded bits as 0’s
1 reveals bits state
can be considered as extracting relevant bits for the task
unneeded bits are considered masked off
can’t go back once masked
OR masks
0 reveals relevant bit state
1 hides unneeded bits as 1’s
can be considered as extracting relevant bits
unneeded bits are masked on
used in LAN IP address allocation
XOR masks
flip selected bits and leave unneeded bits
if the same mask is applied using XOR twice the bit string returns to its original state
can be used for encryption
reversible given same mask
Bit shifting
each shift left is equivalent to multiplying by 2(10) or 10(2)
each shift right is equivalent to dividing by 2(10) or 10(2)
any bits to flow out of scope are dropped