Binary to Denary Conversions

Binary Conversion Table

The image above is an example of a table we can use to convert 8-bit binary numbersreferred to as bytes to denary. Each individual bit is put into each column in the same order as written. Any columns with a 1 should have their values added together. The resulting value is the denary conversion. To convert from denary to binary, take the number you wish to convert and starting in the left most column try subtracting the number from the one you wish to convert. If it can be done without producing a negative put a 1 in the column, if you cannot, put a 0. Once the remainder is 0, add 0s to any remaining columns. The resulting number is the binary conversion. If you want to convert above 8-bit numbers, each column's denary value is calculated as 2 raised to the power of the column starting from the right and at 0.

Binary Addition

Example of Binary Addition using Long Addition

In primary school we are taught to use long addition to sum numbers on paper. The practice relies on the concept of carrying digits to other columns when the simple addition excedes 10. We can use the same technique to add binary numbers just instead of carrying when exceding 10, we do this at 1. The best way to visualise this is with a couple of rules whenn carrying. First, when adding two 1s in a column, the answer is 0 carry 1. Secondly, when adding three 1s in a columnfrom a previous carry, the answer is 1 carry 1.

Binary Subtraction Using 2's Complement

Example of 2's Complement

Subtraction in binary is a little hard as it is not as intuitive as the addition. To subtract two binary numbers we use a method known as 2's complement. 2's complement is a way of expressing a binary number as a negative. After doing this conversion, you can just add the two numbers and it will give the same answer as if the two numbers were subtracted in denary. To find 2's complement, you begin by inverting each bit in the numberif the bit is a 0 it becomes 1, and vice versa and then add 1.

Binary to Hexadecimal Conversions

Denary to Hexadecimal Conversion Table

Hexadecimal is another base system used in programming. Just like binary and denary hexadecimal creates a new column when it's limit15 is reached. However, as the base system is higher than our standard systemdenary, we use lettersA-F to express the numbers 10-15 so that they can be single digits.

To convert from binary to hexadecimal, split the 8-bit number into two 4 bit numbers and convert these numbers to denary. For any number greater than 9 remember to use the letter assignation for hexadecimal. To convert from binary to denary, take the left digit and multiply it by 16, then add the second digit. If you want to convert hexadecimal numbers with more than two digits to denary, you take each digit and multiply it's denary value by 16 raised to the power of digits left to convert. The easiest way to convert from denary to hexadecimal is by first converting to binary, and then hexadecimal.