Boolean Algebra

Number systems

We humans (and selected Alien species) use the decimal number system. What this means is that all the numbers we write down consists of the 10 digits 0 to 9. In other words when we count and get to 9, we start again with 0. Of course to show the difference between zero and ten, we also need to add another digit to the left of the 0 (starting with 1, incrementing to 9 and then go back to 0 plus yet another digit!) This can go on forever… (0..9, 10..99, 100..999, 1000..9999 ….)

Now because our computer friends are not so clever as ourselves, they can only count from 0 to 1. Thus when they count it looks as follows: 0, 1, 10, 11, 100, 101, 110, 111, 1000, … this is known as the binary system is usually shown with a ‘b’ at the end (e.g. 101b). This is to know the difference between 10 (ten) and 10b (two).

Another system programmers use, is the hexadecimal system. This is really for clever persons, cause they count with 16 digits! But wait, there exists only 9 different digits – how do they do it? Simple, when the digits are finished, just use letters. This is how you count in hexadecimal from zero to twenty: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, 10, 12, 13, 14. To show that the numbers are hexadecimal, you can either add an ‘h’ after the value (e.g. 10h), or add a 0x in front of it (e.g.0x10).

Boolean Operations

When we do math, we like to use plus, minus, multiply and divide. Computers however like to do others things, namely: AND, OR, XOR and NOT.

The easiest way to get to know these operations is by looking at some examples: Please note that the orders of these operations don’t matter (thus: 1 AND 0 = 0 AND 1)

1 AND 1 = 1
1 AND 0 = 0

1 OR 1 = 1
1 OR 0 = 1

1 XOR 1 = 0
1 XOR 0 = 1

NOT 1 = 0
NOT 0 = 1

0011b AND 1110b = 0010b
0011b OR 1110b = 1111b
0011b XOR 1110b = 1101b
NOT 0011b = 1100b

Bits and bytes

What is a bit?
A bit is either a 1 or a 0. E.g. the binary value 1010b consists of 4 bits. We call the bit on the left side the most significant bit (MSB) and the bit on the right side the least significant bit (LSB). When the MSB bit in our example is a 1 (as it is), it will represent a decimal value of 8, while the LSB can only represent a maximum value of 1.

What is a byte?
A byte is 8 bits. The maximum value that can be represented by 8 bits is 1111 1111b = 255 (you will see that I’ve put a space after 4 bits, this makes it easier to read.)

What is a kilobyte?
A kilobyte is 1024 bytes (not 1000 bytes, but close.) The reason why it’s not exactly 1000 bytes, is because computers count in binary and everything work in 2’s. E.g. if you buy RAM or a flash disk it will have a value of: 2MB / 4MB / 8MB / 16MB / 32MB / 64MB / 128MB / 256MB / 512MB / 1024MB…. As you can see, using a value of exactly 1000 for a kilobyte would just complicate things in the binary world.

What is a megabyte?
A megabyte is 1024 kilobytes. What is a gigabyte? A gigabyte is 1024 megabytes.

If I right click on my hard drive and choose properties, it shows:
Capacity: 41,457,427,200 bytes 38.3GB
Intuitively you would think this must be a 41GB hard drive, but it only says 38.3GB!

Let’s do the math:
41,157,427,200 bytes
= 41,157,427,200 / 1024 kB
= 40,192,800 / 1024 MB
= 39,250.78 / 1024 GB
= 38.33 GB And there you have it!