Sie sind auf Seite 1von 16

Binary numbers - Conversion formulas and mathematical operations

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.

Binary Numbers Overview


Binary is a number system used by digital devices such as computers, smartphones and tablets. It is also used in digital audio devices such as cd players and MP3 players.

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).

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 Decimalwhich 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), as an 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:

1012 is a binary number and 10110 is a decimal (denary) value.

Once we know the base then it is easy to work out the value, for example:

1012 = 1*22 + 0*21 + 1*20 = 5 (five)

10110 = 1*102 + 0*101 + 1*100 = 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 below.

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 table 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*27 + 0*26 + 0*25 + 1*24 + 1*23 + 1*22 + 0*21 + 1*20 = 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 with a remainder of 1


78 ÷ 2 = 39 with a remainder of 0
39 ÷ 2 = 19 with a remainder of 1
19 ÷ 2 = 9 with a remainder of 1
9÷2=4 with a remainder of 1
4÷2=2 with a remainder of 0
2÷2=1 with a remainder of 0
1÷2=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:

1. complement each digit in turn (change 1 for 0 and 0 for 1).


2. 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 (23510 - 10210)

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 13310

So the full calculation in decimal is 23510 - 10210 = 13310 (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).

1. Apply two's complement to the larger number.


2. Add this value to the smaller number.
3. Change the sign bit (MSB) to zero.
4. Apply two's complement to value to get final result.
5. The most significant bit (sign bit) now indicates the value is negative.

For example let's do the following subtraction 10010101 - 10110100 (14910 - 18010)

The process is as follows:


Now we can convert this value into a negative decimal, which gives -3110

So, the full calculation in decimal is 14910 - 18010 = -3110 (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 1110 x 710)
which gives us 1001101, now we can convert this value into decimal, which gives 7710

So the full calculation in decimal is 1110 x 710 = 7710 (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 910 ÷ 310)

which gives us 0011, now we can convert this value into decimal, which gives 310

So the full calculation in decimal is 910 ÷ 310 = 310 (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.
Converting binary to decimal number or decimal to binary number is an easy task. But, you need to be careful that not mix up the two sets of numbers. For instance, if you write the digits 10 on the page it could mean the number “ten” if we assume it to be a decimal number, or it could equally be a “1” and a “0” together in binary, which is
equal to the number two in the weighted decimal format from above table.

DecimalNumber=nthbit×2n−1DecimalNumber=nthbit×2n−1
Binary to Decimal Formula:

n=bnqn+bn−1qn−2+…..+b2q2+b1q1+b0q0+b−1q−1+b−2q−2n=bnqn+bn−1qn−2+…..+b2q2+b1q1+b0q0+b−1q−1+b−2q−2
Where, N is decimal equivalent,
b is the digit,
q is the base value that starts from most significant digit order qn to least significant order q-1, q-2, …..
To convert binary to decimal the following chart is used and binary is noted as per the given decimal number.

Binary 0 1 10 11 100 101 110 111 1000 1001 1010 1011 1100 1101 1110 1111

Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

So, for instance, if you use a binary number string it should add the subscript “2” to denote a base 2 number so the binary n umber would be written as 102102. Likewise if it was a standard decimal number it would add the subscript “10” to denote a base 10 and written as 10101010.
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 table like that below:

128 64 32 16 8 4 2 1

1 0 0 1 1 1 0 1

To convert, you simply take a value from the top row wherever there is a 1 below and then add the values together.
SOLVED EXAMPLES
Question 1: Convert 0110101 to decimal
Solution:
Given Binary number is 0110101
0110101 = (0 ×× 2626) + (1 ×× 2525) + (1 ×× 2424) + (0 ×× 2323) + (1 ×× 2222) + (0 ×× 2121) + (0 ×× 2020)
= 0 + 32 + 16 + 0 + 4 + 0 + 0
= 52
Answer: Binary Number 0110101 = 52 Decimal number
DECIMAL TO BINARY FORMULA
Decimal to binary conversion is a long process which is usually done by dividing the decimal number to 2. Continuous division of integers is carried out until the reminder reaches to 0 or 1. Note down all the reminders in reverse order and arrive at a binary number corresponding that is almost near to given decimal number.

Here are few decimal numbers and their corresponding binary numbers –

Decimal Numbers Binary Numbers

0 0000

1 0001

2 0010

3 0011
4 0100

5 0101

6 0110

7 0111

8 1000

9 1001

10 1010
11 1011

12 1100

13 1101

14 1110

15 1111

SOLVED EXAMPLES
Question 1: Convert 25 in to binary system?

Solution:

Given decimal number is 25.


Divide this number by 2 until the reminder is 0 or 1.
2 | 25
________
2 | 12……………1
________
2 | 6…………….0
________
2 | 3…………….0
________
1…………….1
So, the binary equivalent is,
(25) 1 0 = (11001) 2

Das könnte Ihnen auch gefallen