Home

Binary and Hexadecimal are necessary evils in computing. We will see numerous examples over this course where the magic numbers 128, 256, 512, 1024, 2048, 4096 ...16536 appear in computing, For example 1024 well-known ports in networking, 4G memory limit with 32bit processors, 512 byte sectors on a hard disk and 4096 bytes in a cluster on a hard disk formatted in NTFS. These all relate to binary.

Note this is our next taught lesson so if you don't get anything I will clear it up then, OR ask on the forum and I will answer.

What is the Decimal System?

Since we learnt how to count to ten and all the rules of the decimal system, most of us have forgotten why the number 145 has its value One Hundred and Forty Five and that it is a Base 10 number.

Base 10 simply means there are 10 digits available for counting - 0 to 9. When the digits reach their maximum we move 1 column to the left and continue counting from 10 etc.

So we can count in different bases. What is the benefit of that?

Base 2, or Binary, has two digits 0 and 1. These can be represented by switches as off and on (which is basically what a transistor is). One draw back with binary is it takes a lot of digits (or BITS which stands for BInary digIT) to represent large numbers, though this doesn't really affect a CPU running at over 2GHz.

Base 16, or Hexadecimal, has 16 digits 0 to F and is closely related to binary as we will see later when converting. Hex numbers can represent very large numbers with fewer digits - Ideal for programming that binary code in.

So how do we convert from a Base back to Base 10?

A simple table will convert any Base number to Base 10 and back again.

  1. Draw a table with 3 rows and 8 columns.
  2. In the top row write in the base you want to convert from (i.e. 2 for Binary), write in the powers from right to left beginning with 0,1,2,3,4 etc.
  3. In the middle row calculate the values for each column. Remember two rules. Any number to the power of 0 is equal to 1 and any number to the power of 1 is equal to itself.
  4. Now write in the number you wish to convert. This is binary so I can only use the digits 0 and 1. I chose the binary number 00010110 which I can see from the table that it is equivalent to decimal 22.

Will this work for any Base conversion to Decimal?

Yes! For example the Base 10 number 145

Base 10 Table (Decimal)



What do you think the values are for the 4 and the 5?

		1 x 100 = 100 +
		4 x 10 = 40
		5 x 1 = 5
		=145 Base 10
		

I wonder what the value of 145 would be if it were base 16?

Base 16 Table (Hexadecimal)



		1 x 256 =256+
		4 x 16 = 64
		5 x 1 = 5
		= 325 Base 10
		
		So 145 Base 16  is equivalent to 325 Base 10
		

Base 2 (Binary)

Base 2 has only two digits 0 and 1. This is important for digital equipment because the electrical components (mostly transistors) can be in one of two states On or Off like a switch and therefore they can communicate binary sequences down busses to other components which can then decode signals.

Every letter and symbol in modern languages has been coded with a value that can be transmitted in binary. This system is called Unicode.

For example the capital letter "A" has the decimal value of 65 in the unicode chart. To transmit this as data on a bus that is 8 bits wide it must be in binary. I'll use a Base 2 table to do the conversion.

Base 2 Table (Binary)



		Note I have produced the number with 8 Bits (BI nary digi TS)
		So 01000001 Base 2  would be from the table above

		1 x 64 = 64 +
		1 x 1 = 1
		= 65 Base 10  or the letter "A" in Unicode
		
If I ordered the following

00011000 Base 2 Apples OR
18 Base 16 Apples OR
30 Base 8 Apples OR
24 Base 10 Apples

I would get 24 Apples in every case (Base 10 of course.)


8 Hex Digits = 32 Bits = 4 Bytes, the range of positive numbers is from 0 to 4 294 967 296

4 Bits, or a Nyble, has the range of 0 to15 Positive Integers (Positive whole numbers).

1 Digit in Hexadecimal ALSO has the range of 0 to 15 Positive Integers (Positive whole numbers).

Knowing this we can convert Binary to Hex and Hex to Binary fairly easily by breaking binary into 4 bit chunks.


Consider this in Base 2;
There are 10 types of people in the world. Those that understand binary and those that don't!

Further Reading

Count to 1024 using your fingers

Why 32 bit CPUs can only use 4 GB of system memory

Aliens!!?

Send someone a coded message.