Notizen
Binary Conversion
Inhalt der Notizen (1)
Seite 1
Binary Conversions
The Binary Numbering System
In everyday
life, we normally use a numbering system that is constructed on multiples of
ten. We call this numbering system the Base-10 or decimal numbering
system. Base-10 numbering systems dictate that the numbering scheme begins to
repeat after the tenth digit (in our case, the number 9). When we count, we
usually count "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, ..."
There's
more to the numbering scheme than just counting, though. In grade school, we
all were taught that each digit to the left and right of the decimal point is
given a name which identifies that digit's placeholder. For right now, let's
just consider digits to the left of the decimal, or positive numbers. Remember
that the first digit to the left of the decimal point is called the
"ones" digit. It is followed by the "tens" digit, followed
by the "hundreds", followed by the "thousands", and on and
on. What they probably didn't tell you in grade school is that each placeholder
(ones, tens, hundreds, thousands, etc.) actually represents a multiple of ten
(remember -- "Base-10"?).
Each
placeholder can be represented by an exponent of ten. For instance, the
expression 100 represents the "ones" position, the
expression 101 represents the "tens" position, the
expression 102 represents the "hundreds" position and so
on.
We can
begin to see this more clearly if we break down a number into exponents of ten.
Let's take a look at the following number: 7408. Starting at the decimal point,
we'll work our way left. The first digit to the left of the decimal point is 8.
However, we can represent this using the arithmetic expression 100*8.
Remember: Anything to the zero power is always equal to 1.
If we were to calculate that last expression out it would look like this: 100*8=1*8=8.
Examine the following table to see exponential expressions for the other
digits:
Number
7
4
0
8
Position
Name
Thousands
Hundreds
Tens
Ones
Exponential
Expression
103*7
102*4
101*0
100*8
Calculated
Exponent
1000*7
100*4
10*0
1*8
Table 1:
Decimal Placeholders
Like the
decimal numbering system, binary numbering is also based on powers of a number.
However, unlike the decimal system (which is based on multiples of ten), the
binary numbering system is based on multiples of two. It is a Base-2 numbering
system. Remember -- when counting in decimal, the numbering scheme repeats
after the tenth digit (the number 9). In binary numbering the numbering scheme
repeats after the second digit (the number 1). Let's count to five in
binary: "0, 1, 10, 11, 100, 101"
Also like
the decimal numbering system, binary numbering includes names for digit
placeholders. Instead of "ones, tens, hundreds, thousands, etc.",
binary has "ones, twos, fours, eights, sixteens, etc." If the binary
system is based on powers of 2, why is there still a "ones" position?
Remember: Anything to the zero
power is always equal to 1. So, in binary, the "ones"
position is represented by the exponential expression 20! Take a
look at the following table to see how the binary number 1101 is broken into
exponential expressions:
Number
1
1
0
1
Position
Name
Eights
Fours
Twos
Ones
Exponential
Expression
23*1
22*1
21*0
20*1
Calculated
Exponent
8*1
4*1
2*0
1*1
Table 2:
Binary Placeholders
Binary
to Decimal Conversions
So, how can
I convert the binary number 1101 to a good-old decimal number? The best way to
to this is construct a table in which you can do some simple arithmetic
operations to solve the conversion! Let's try it!
1.
First, I want to write the binary number in
a row, separating the digits into columns:
Number
1
1
0
1
2.
Next,
I want to decide whether each digit placeholder is "ON" or
"OFF." The reason for this will become a little clearer in a few
minutes, but for right now just remember that a "1" is "ON"
and a "0" is "OFF." When we calculate the exponential
expressions, we don't have to calculate any digit placeholders that are turned
off:
Number
1
1
0
1
ON/OFF
ON
ON
OFF
ON
3.
In
the third step, we write the exponential expressions ("powers of
two") that represent each placeholder and multiply each expression by 1.
We do this only for the placeholders that are turned ON. For the
placeholders which are turned OFF, we simply bring down the zero from the number
itself:
Number
1
1
0
1
ON/OFF
ON
ON
OFF
ON
Exponential
Expression
23*1
22*1
0
20*1
4.
Now,
we can calculate the exponents to get a simple multiplication expression for
each placeholder. Again, we do this only for placeholders which
are turned "ON." Again, we bring down the zero if the placeholder is
turned "OFF":
Number
1
1
0
1
ON/OFF
ON
ON
OFF
ON
Exponential
Expression
23*1
22*1
0
20*1
Calculated
Exponent
8*1
4*1
0
1*1
5.
In
the fifth step, we solve the multiplication expressions from step #4. Again, we
bring down any zeros for placeholders which are turned OFF:
Number
1
1
0
1
ON/OFF
ON
ON
OFF
ON
Exponential
Expression
23*1
22*1
0
20*1
Calculated
Exponent
8*1
4*1
0
1*1
Solved
Multiplication
8
4
0
1
6.
In
the final step, we add all the multiplication answers from step #5 together to
get our decimal number!
Number
1
1
0
1
ON/OFF
ON
ON
OFF
ON
Exponential
Expression
23*1
22*1
0
20*1
Calculated
Exponent
8*1
4*1
0
1*1
Solved
Multiplication
8
4
0
1
Add to Calculate
Decimal Value
8+4+0+1=13
Let's take a look at another conversion.
This time, we'll try 101101:
Number
1
0
1
1
0
1
ON/OFF
ON
OFF
ON
ON
OFF
ON
Exponential
Expression
25*1
0
23*1
22*1
0
20*1
Calculated
Exponent
32*1
0
8*1
4*1
0
1*1
Solved
Multiplication
32
0
8
4
0
1
Add to Calculate
Decimal Value
32+0+8+4+0+1=45
Why
not try some on your own? Convert the following from binary to decimal.
1. 111
2. 1011
3. 10111
4.11100
Decimal to Binary Conversions - Using
Division
The second method of converting from decimal
to binary also involves constructing a table. This time, instead of using
binary placeholder exponential expressions, we'll do some simple division.
Again, let's use the decimal number 97 as our example:
1.
The
first step in the conversion is to take the decimal number and divide it by 2.
Put the division expression in the upper left-most cell of our table. Take the
quotient of the division result and put it in the second cell of the row. Put
the remainder in the last cell of the row. Important: NEVER carry
your divisions past the decimal point!
Decimal
Number=97
Division Expression
Quotient
Remainder
97/2
48
1
2.
For
each subsequent row, we take the quotient from the previous row and divide it
by two. We put the new quotient in the second cell of the row and put the
remainder in the last cell of the row:
Decimal
Number=97
Division Expression
Quotient
Remainder
97/2
48
1
48/2
24
0
24/2
12
0
12/2
6
0
6/2
3
0
3/2
1
1
1/2
0
1
3.
The
last step in the process is concerned only with the last column in our table --
the "Remainder" column. Notice that the remainder column only has
ones or zeros. Also note that the cell in the remainder column of the last row must
be a "1". If we read the 1s and 0s in the remainder column
from the bottom to the top, we'll have our binary number!
Decimal
Number=97
Division Expression
Quotient
Remainder
Direction
97/2
48
1
48/2
24
0
24/2
12
0
12/2
6
0
6/2
3
0
3/2
1
1
1/2
0
1
Binary
Number=1100001
Binary addition
Adding binary numbers is a very simple task, and very
similar to the longhand addition of decimal numbers. As with decimal numbers,
you start by adding the bits (digits) one column, or place weight, at a time,
from right to left. Unlike decimal addition, there is little to memorize in the
way of rules for the addition of binary bits:
0 + 0 = 0
1 + 0 = 1
0 + 1 = 1
1 + 1 = 10
1 + 1 + 1 = 11
Just as with
decimal addition, when the sum in one column is a two-bit (two-digit) number,
the least significant figure is written as part of the total sum and the most
significant figure is "carried" to the next left column. Consider the
following examples:
. 11 1 <--- Carry bits -----> 11
. 1001101 1001001 1000111
. + 0010010 + 0011001 + 0010110
. --------- --------- ---------
. 1011111 1100010 1011101
The addition
problem on the left did not require any bits to be carried, since the sum of bits
in each column was either 1 or 0, not 10 or 11. In the other two problems,
there definitely were bits to be carried, but the process of addition is still
quite simple.
Sign and Magnitude
In Sign and Magnitude
coding we use one bit to represent the sign of the number and the remaining
(n-1) bits to represent the size (the magnitude).
The bit used to
represent the sign of the number is called the sign bit. The bit used to
represent the sign of the number is called the sign bit. The sign bit is the
leftmost bit (ie. in the most significant position). If the sign bit is 0 then
this means that it is a positive number, and if the sign bit is 1 then this
means that it is a negative number.
Example
Using 8 bits and sign
& magnitude:
29 would be
represented as: 0001 1101
-29 would be
represented as 1001 1101.
Converting
back to Decimal
To convert from Sign
& Magnitude back to decimal :
(1) Take off the
leftmost bit. This will determine the Sign (0 for positive and 1 for negative).
(2) Convert the
remaining n-1 bits from binary to decimal (the same way as unsigned binary).
Question
Using Sign &
Magnitude, convert the following into decimal form: (use paper for working).
(1) 10101100
Two's Complement.
To convert positive
integers using two's complement simply convert to binary and pad to the left
with zeros to the required bit size.
To convert negative
integers using two's complement:
·
Convert to binary, then pad to the left with
zeros to the require bit size.
·
Invert all bits.
·
Add 1.
Binary Coded Decimal
Short for binary-coded
decimal, a format for representing decimal numbers (integers) in which each
digit is represented by four bits
(a nibble ).
For example, the number 375 would be represented as:
0011 0111 0101
Below is a table of the decimal numbers 0
through 9 and the binary conversion.
Decimal
BCD
0
0000
1
0001
2
0010
3
0011
4
0100
5
0101
6
0110
7
0111
8
1000
9
1001
Informationen
- Beschreibung
- descriptive notes on all the conversion of binary
- Erstellt von
- Craig Thompson
- Aufrufe
- 73
- Tags
- Bewertung