Denary is the base-10 number system which we use everyday. It has 10 different digits: 0,1,2,3,4,5,6,7,8 and 9. This is used by people because it is easy to understand and learn.
Computers use binary to store all data and instructions. Each of the binary numbers is called a bit (Binary digit) Computers use binary and logic gates to make calculations. Binary is in 1s and 0s. 1 represents ON and 0 represents OFF. You can use these basic inputs/outputs and boolean logic to create a system for operations. Binary is usually written in 8 bits which means it has 8 digits. E.g. 01001001
We can convert from binary to denary or from denary to binary using the table below:
In order to find out what the denary equivalent of a binary string is, we need to put the binary string and the denary equivalents into the table and add together the column values where there is a ’1’. Here is an example of the conversion of 00110100 into denary:
32 + 16 + 4 = 50 Therefore 00110100 = 50
The method to convert from denary to binary is less straightforward, but can be understood with some practice. The method you will learn here is to half the denary number, and if there is a reminder, record a 1, otherwise leave it as a 0. You keep halving until you reach 0. Here is an example of converting 231 into binary:
|231 ÷ 2 = 115.5||1|
|115 ÷ 2 = 57.5||1|
|57 ÷ 2 = 28.5||1|
|28 ÷ 2 = 14||0|
|14 ÷ 2 = 7||0|
|7 ÷ 2 = 3.5||1|
|3 ÷ 2 = 1.5||1|
|1 ÷ 2 = 0.5||1|
This tells us that 231 = 11100111
Sometimes it is more efficient to add 2 binary numbers without having to convert them into denary and convert back to binary. In order to do so, there are some mathematical laws that need to be followed:
Here is an example of the addition of 01110100 (116) + 10001010 (138):
Here is another example of binary addition:
In this case the result is not in the form of an 8-bit number. If it goes beyond the 8-bit range it is known as an overflow error. An overflow error is caused when the processor does not have enough bytes available to process an instruction. There is an extra bit which cannot fit into the 8-bits as the result is greater than 255 of 11111111
Hexadecimal is a base-16 number system meaning meaning it is made up of 16 different symbols: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E and F. Hexadecimal is often used by programmers as it is easier to read and quicker to use.
|Denary (Base-10)||Binary (Base-2)||Hexadecimal (Base-16)|
You will also need to know how to convert hexadecimal to other number systems. In this example we will convert 24 in hexadecimal to denary. We need to use a column method like this:
|16 x 2 = 32||4 x 1 = 4|
32 + 4 = 36 This means 24 in hexadecimal is 36 in denary.
Here is another example using a letter from the hexadecimal table:
|16 x 3 = 48||13 x 1 = 13|
48 + 13 = 61
This means 3D in hexadecimal is 61 in denary.
There are many ways to convert denary to hexadecimal but you should learn this method. In this example we will convert from 45 in denary to hexadecimal. First we convert 45 into binary using the method from before which you can learn about here: (If needed go back and take a look at converting using binary to remind yourself)
45 is 00101101. We then convert that into 2 nibbles and calculate the value of each nibble.
|0+0+2+0 = 2||---||8+4+0+1 = 13 = D|
We then just put the two results next to each other which gives us: 2D. This means 45 in denary is 2D in hexadecimal.
Here is another example with 237. Using the other method we know 237 is 11101101. We now convert it into 2 nibbles and calculate the value of each nibble.
|8+4+2+0 = 14 = E||---||8+4+0+1 = 13 = D|
We then just put the two results next to each other which gives us: ED. This means 237 in denary is ED in hexadecimal.