Binary numbers  Conversion formulas and mathematical operations.
Welcome to our binary numbers guide.
In this section we will explain what binary is and show you how to convert between binary and decimal (denary) numbers.
We will also show you how to perform various mathematical operations on binary numbers, including multiplication and division.
Spread the word, share this on your social networks!
Binary Numbers Overview
Binary is a number system used by digital devices like computers, cd players, etc.
Binary is Base 2, unlike our counting system decimal which is Base 10 (denary).
In other words, Binary has only 2 different numerals (0 and 1) to denote a value, unlike Decimal which has 10 numerals (0,1,2,3,4,5,6,7,8 and 9).
Here is an example of a binary number: 10011100
As you can see it is simply a bunch of zeroes and ones, there are 8 numerals in all which make this an 8 bit binary number. Bit is short for Binary Digit, and each numeral is classed as a bit.
The bit on the far right, in this case a 0, is known as the Least significant bit (LSB).
The bit on the far left, in this case a 1, is known as the Most significant bit (MSB)
notations used in digital systems:
4 bits = Nibble
8 bits = Byte
16 bits = Word
32 bits = Double word
64 bits = Quad Word (or paragraph)
When writing binary numbers you will need to signify that the number is binary (base 2), for example, let's take the value 101. As it is written, it would be hard to work out whether it is a binary or decimal (denary) value. To get around this problem it is common to denote the base to which the number belongs, by writing the base value with the number, for example:
101_{2} is a binary number and 101_{10} is a decimal (denary) value.
Once we know the base then it is easy to work out the value, for example:
101_{2} = 1*2^{2} + 0*2^{1} + 1*2^{0} = 5 (five)
101_{10} = 1*10^{2} + 0*10^{1} + 1*10^{0} = 101 (one hundred and one)
One other thing about binary numbers is that it is common to signify a negative binary value by placing a 1 (one) at the left hand side (most significant bit) of the value. This is called a sign bit, we will discuss this in more detail in the next part of the tutorial.
Electronically binary numbers are stored/processed using off or on electrical pulses, a digital system will interpret these off and on states as 0 and 1. In other words if the voltage is low then it would represent 0 (off state), and if the voltage is high then it would represent a 1 (on state).
Converting binary to decimal
To convert binary into decimal is very simple and can be done as shown below:
Say we want to convert the 8 bit value
10011101 into a decimal value, we can use a formula like that below:
128 
64 
32 
16 
8 
4 
2 
1 
1 
0 
0 
1 
1 
1 
0 
1 
As you can see, we have placed the numbers 1, 2, 4, 8, 16, 32, 64, 128 (powers of two) in reverse numerical order, and then written the binary value below.
To convert, you simply take a value from the top row wherever there is a 1 below, and then add the values together.
For instance, in our example we would have
128 + 16 + 8 + 4 + 1 = 157.
For a 16 bit value you would use the decimal values 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768 (powers of two) for the conversion.
Because we know binary is base 2 then the above could be written as:
1*2^{7} + 0*2^{6} + 0*2^{5} + 1*2^{4} + 1*2^{3} + 1*2^{2} + 0*2^{1} + 1*2^{0} = 157.
Converting decimal to binary
To convert decimal to binary is also very simple, you simply divide the decimal value by 2 and then write down the remainder, repeat this process until you cannot divide by 2 anymore, for example let's take the decimal value 157:
157 ÷ 2 = 78
78 ÷ 2 = 39
39 ÷ 2 = 19
19 ÷ 2 = 9
9 ÷ 2 = 4
4 ÷ 2 = 2
2 ÷ 2 = 1
1 ÷ 2 = 0

with a remainder of 1
with a remainder of 0
with a remainder of 1
with a remainder of 1
with a remainder of 1
with a remainder of 0
with a remainder of 0
with a remainder of 1

< to convert write this remainder first.

Next write down the value of the remainders from bottom to top (in other words write down the bottom remainder first and work your way up the list) which gives:
10011101 = 157
Adding binary numbers
Adding binary numbers is very similar to adding decimal numbers, first an example:
Let's look at the above example step by step:
1 + 1 = 0 (carry one)
1 + 1 (+ the carry) = 1 (carry one)
0 + 1 (+ the carry) = 0 (carry one)
1 + 0 (+ the carry) = 0 (carry one)
1 + 0 (+ the carry) = 0 (carry one)
0 + 1 (+ the carry) = 0 (carry one)
1 + 0 (+ the carry) = 0 (carry one)
The last carry is placed at the left hand side of the result giving:
10000010
Subtracting binary numbers
The most common way of subtracting binary numbers is done by first taking the second value (the number to be subtracted) and apply what is known as
two's complement, this is done in two steps:
 complement each digit in turn (change 1 for 0 and 0 for 1).
 add 1 (one) to the result.
note: the first step by itself is known as
one's complement.
By applying these steps you are effectively turning the value into a negative number, and as when dealing with decimal numbers, if you add a negative number to a positive number then you are effectively subtracting to the same value.
In other words 25 + (8) = 17, which is the same as writing 25  8 = 17.
An example, let's do the following subtraction
11101011  01100110 (235
_{10}  102
_{10})
note: When subtracting binary values it is important to maintain the same amount of digits for each number, even if it means placing zeroes to the left of the value to make up the digits, for instance, in our example we have added a zero to the left of the value
1100110 to make the amount of numerals up to 8 (one byte)
01100110.
First we apply two's complement to 01100110
which gives us
10011010.
Now we need to add
11101011 + 10011010, however when you do the addition you always disregard the last carry, so our example would be:
which gives us
10000101, now we can convert this value into decimal, which gives
133_{10}
So the full calculation in decimal is 235
_{10}  102
_{10} = 133
_{10} (correct!)
Negative numbers
The above example is subtracting a smaller number from a larger number.
If you want to subtract a larger number from a smaller number (giving a negative result), then the process is slightly different.
Usually, to indicate a negative number, the most significant bit (left hand bit) is set to 1 and the remaining 7 digits are used to express the value. In this format the
MSB is referred to as the
sign bit.
Here are the steps for subtracting a large number from a smaller one (negative result).
 Apply two's complement to the larger number.
 Add this value to the smaller number.
 Change the sign bit (MSB) to zero.
 Apply two's complement to value to get final result.
 The most significant bit (sign bit) now indicates the value is negative.
For example let's do the following subtraction
10010101  10110100 (149
_{10}  180
_{10})
The process is as follows:
Now we can convert this value into a negative decimal, which gives
31_{10}
So, the full calculation in decimal is 149
_{10}  180
_{10} = 31
_{10} (correct!)
Multiplying binary numbers
Binary multiplication can be achieved in a similar fashion to multiplying decimal values.
Using the long multiplication method, ie, by multiplying each digit in turn, and then adding the values together.
For example, lets do the following multiplication:
1011 x 111 (decimal
11_{10} x 7_{10})
which gives us
1001101, now we can convert this value into decimal, which gives
77_{10}
So the full calculation in decimal is
11_{10} x 7_{10} =
77_{10} (correct !!)
note: Notice the pattern in the partial products, as you can see multiplying a binary value by two can be achieved by shifting the bits to the left and adding zeroes to the right.
Dividing binary numbers
Like multiplication, dividing binary values is the same as long division in decimal.
For example, lets do the following division:
1001 ÷ 11 (decimal
9_{10} ÷ 3_{10})
which gives us
0011, now we can convert this value into decimal, which gives
3_{10}
So the full calculation in decimal is
9_{10} ÷ 3_{10} =
3_{10} (correct !!)
note: Dividing a binary value by two can also be achieved by shifting the bits to the right and adding zeroes to the left.
Spread the word, share this on your social networks!