Computer science > binary, denary and hexadecimal

How Computers Read Data

Binary

Hexadecimal
<
>
The number system you are probably familiar with is called base 10. This simply means that there are 10 possible digits we can use that range from 0 to 9. From there, multiple base 10 digits are combined to form new numbers. For example fiftyeight can be made from a 5 and an 8, making 58. However, computers need a different, more logical way to process data.
Denary is the number system you are used to (base 10). Denary can also be referred to as decimal but computers can't read this.
Binary is also known as base 2 because there are only two possible digits 0 and 1. Simply, 0 means not present and 1 means present. We will look at Binary in more detail later on. Computers read data in binary because a computer's CPU (central processing unit) is made of millions of small switches which can either be on (1) or off (0).
Hexadecimal is known as base 16 because there are 16 available digits that range from 0 to F. You may have seen it resemble colour data because it is a great way to resemble red, green and blue values. We use hexadecimal as it allows us to write things more easily than binary which requires a large number of digits quickly. It is often indicated that hexadecimal is being used with a 'H' or '0x'
Denary is the number system you are used to (base 10). Denary can also be referred to as decimal but computers can't read this.
Binary is also known as base 2 because there are only two possible digits 0 and 1. Simply, 0 means not present and 1 means present. We will look at Binary in more detail later on. Computers read data in binary because a computer's CPU (central processing unit) is made of millions of small switches which can either be on (1) or off (0).
Hexadecimal is known as base 16 because there are 16 available digits that range from 0 to F. You may have seen it resemble colour data because it is a great way to resemble red, green and blue values. We use hexadecimal as it allows us to write things more easily than binary which requires a large number of digits quickly. It is often indicated that hexadecimal is being used with a 'H' or '0x'
Let's learn how to convert to and from binary.

Denary to Binary

Binary to Denary
<
>
First start with a number. In this example, we are going to use the number 58.
Draw a table. When working with binary, you need to take the number of bits into account. We are going to use 8 bits, so there will be 8 columns to the table. When numbering the table, go from right to left, starting from one and doubling until you reach the end.
Draw a table. When working with binary, you need to take the number of bits into account. We are going to use 8 bits, so there will be 8 columns to the table. When numbering the table, go from right to left, starting from one and doubling until you reach the end.
128 
64 
32 
16 
8 
4 
2 
1 
As you can see, there are 8 columns for the eight bits. Sometimes, you may need less or more columns, but 8 bits is a good place to start.
Now, we are going to go across each column from left to right this time, and put a 1 or a 0 to show if the number is present. If the number is bigger or the same as than the number you want to write (58 in this case), then put a 0. If it is smaller put a 1 and subtract that number from the main number. For example, 128 is bigger than 58 so we put a 0. So is 64, but 32 isn't. So we put a 0 in 64 and a 1 in 32. We then minus 32 from 58 and get 26. Let's continue to move on, but with the number 26 instead. 16 fits into 26, so we put a 1 there and subtract 16 from 26 to get 10. 8 fits into 10 so we put a 1 there and subtract 8 from 10 to get 2. 4 is bigger than 2, so it doesn't fit in. We put a 0 there and move on. 2 is the same as our number, so we put a 1 there and now that our number is 0, we put a 0 under every thing to our right.
Now, we are going to go across each column from left to right this time, and put a 1 or a 0 to show if the number is present. If the number is bigger or the same as than the number you want to write (58 in this case), then put a 0. If it is smaller put a 1 and subtract that number from the main number. For example, 128 is bigger than 58 so we put a 0. So is 64, but 32 isn't. So we put a 0 in 64 and a 1 in 32. We then minus 32 from 58 and get 26. Let's continue to move on, but with the number 26 instead. 16 fits into 26, so we put a 1 there and subtract 16 from 26 to get 10. 8 fits into 10 so we put a 1 there and subtract 8 from 10 to get 2. 4 is bigger than 2, so it doesn't fit in. We put a 0 there and move on. 2 is the same as our number, so we put a 1 there and now that our number is 0, we put a 0 under every thing to our right.
128 
64 
32 
16 
8 
4 
2 
1 
0 
0 
1 
1 
1 
0 
1 
0 
Doesn't fit into 58 
Doesn't fit into 58 
Does fit in, our number is now 26 
Does fit in, our number is now 10 
Does fit in, our number is now 2 
Doesn't fit into 2 
Is the same as 2, our number is now 0 
Doesn't fit into 0 
There you go! 58 in binary is 00111010.
First start with a binary number. In this example, we are going to use the binary number 01010011.
Draw a table. When working with binary, you need to take the number of bits into account. We are going to use 8 bits because there are 8 digits, so there will be 8 columns to the table. Be careful to count the digits, sometimes it may have more or fewer bits. When numbering the table, go from right to left, starting from one and doubling until you reach the end, then put your number into the correct slots in the table.
Draw a table. When working with binary, you need to take the number of bits into account. We are going to use 8 bits because there are 8 digits, so there will be 8 columns to the table. Be careful to count the digits, sometimes it may have more or fewer bits. When numbering the table, go from right to left, starting from one and doubling until you reach the end, then put your number into the correct slots in the table.
128 
64 
32 
16 
8 
4 
2 
1 
0 
1 
0 
1 
0 
0 
1 
1 
The next step is just a matter of adding. We are going to see which numbers are present and add them together. We can see that 64, 16, 2 and 1 all have ones under them, so they must be present.
64+16+2+1 = 83
So 01010011 is 83 in binary.
64+16+2+1 = 83
So 01010011 is 83 in binary.
Let's learn how to convert to and from hexadecimal.

Denary to Hexadecimal

Hexadecimal to Denary

Hexadecimal to Binary

Binary to Hexadecimal
<
>
Hexadecimal is base 16 so it has digits that range from 0 to F. It starts of like denary, starting at 0 and going to 9, but from 10 to 15 we use letters instead. 10 is A and 15 is F. There are two ways we can convert from Denary to Hexadecimal (or just hex). We can convert it to binary and then to hexadecimal or divide by 16 each time and work it out with the remainder. In this example, we are going to convert via binary. We are going to use the number 58.
First, convert it to binary using the previous method. 58 in binary is 00111010.
We then split this binary number into two 4bit parts, giving us 0011 and 1010.
0011 is 3 in denary.
1010 is 10 in denary.
As we have established, 3 in hexadecimal is 3 and 10 in hexadecimal is A.
Mash these two together and you get 3A. 58 in hexadecimal is 3A!
First, convert it to binary using the previous method. 58 in binary is 00111010.
We then split this binary number into two 4bit parts, giving us 0011 and 1010.
0011 is 3 in denary.
1010 is 10 in denary.
As we have established, 3 in hexadecimal is 3 and 10 in hexadecimal is A.
Mash these two together and you get 3A. 58 in hexadecimal is 3A!
To convert hexadecimal to denary, we simply have to do the reverse. In this example we are going to use F8.
If we split it up we get F and 8.
F is 15 in denary which is 1111 in binary.
8 is 8 in denary which is 1000 in binary.
Put the two together to get 11111000.
11111000 is 248 in denary.
So F8 is 248 in denary.
If we split it up we get F and 8.
F is 15 in denary which is 1111 in binary.
8 is 8 in denary which is 1000 in binary.
Put the two together to get 11111000.
11111000 is 248 in denary.
So F8 is 248 in denary.
Take the binary number 10010100
Since it has 8 digits, you can split it into 2 which would make it 1001 and 0100.
Then you find the hex value for each 4 bit section (nibble) by working out the denary first and then converting to hex and then combine the 2 hex values together to get your number.
1001=9=9
0100=4=4
Therefore, 10010100=94 in hexadecimal
Since it has 8 digits, you can split it into 2 which would make it 1001 and 0100.
Then you find the hex value for each 4 bit section (nibble) by working out the denary first and then converting to hex and then combine the 2 hex values together to get your number.
1001=9=9
0100=4=4
Therefore, 10010100=94 in hexadecimal