# Bitwise Boolean Logic

The new KS3 National Curriculum for *Computing* includes
binary and Boolean logic. If you understand binary and you understand Boolean logic, then you can combine the two. Bitwise operations convert numbers to their binary equivalents and then apply logical operators to them a bit at a time.

You can change the numbers either by clicking on the 0s and 1s, or by typing numbers into the boxes. Try some examples - e.g. 3 OR 5 = 7. Can you see why? Look at the right-most bits - 1 OR 1 = 1. The next bits give 1 OR 0 = 1, and, in the 4 column, 0 OR 1 = 1. This means that the right-most three bits in the answer are 111 - i.e. 7.

This technique is used to *mask* bits to separate binary flags (amongst other things). Give it a try - enter a number and then AND it with 16; the answer will tell you whether the number includes History.

For a more in-depth discussion of this and other related techniques, look at the *Bitwise Logic* page in the *Mathematics* section.

Why not practice your programming skills by creating a program that uses these techniques? Bitwise logic can be used to convert decimal numbers to binary, or you can use Exclusive-OR to encrypt text. This technique is also used in my traffic light and seven-segment display examples to indicate which lights should be lit for each stage in the sequence. Click here to download some curriculum programming examples.