how to turn a singe bit on we could do a simple OR operation: ▪ Regardless of the value of x when we or it with a 1 the result will always be a 1. x or 1 = 1
do an OR operation with these two numbers, the resulting number looks similar but we have switched the individual bit ON. 10110011 00000100 OR 10110111
following binary number and we want to toggle the bit indicated: 0010 0001 ▪ Introduce our new number and bit shift it so it lines up with the one we want to toggle then perform an XOR operation.
need to do first is NOT our new value BEFORE we perform the logical AND. 10011101 11110111 AND 10010101 ▪ Our new number is the same as the original with the bit switched OFF.
Sometimes we may just need to know what a bit value is but not write any changes to the original number: ▪ To do this we introduce a new number as before, bit shift to the bit we want to query and then perform and AND operation ▪ If the number we get back is all zeros, then the bit is a zero. ▪ If the number we get back contains a 1, then the bit is a 1. 10101110 00001000 AND 00001000