Binary Decimals
Download
Report
Transcript Binary Decimals
Fractions in Binary
Fractions
Binary doesn’t just do integers (whole
numbers) it can also be used for fractions
though it isn’t as accurate as decimals in
denary
e.g. 136.75 could be expressed as 136 +
1/2 + 1/4
128 64 32 16 8 4 2 1 . 1/2 1/4 1/8 1/16
1
0 0
0 1 0 0 0.
1
1 0
0
This is binary notation – the
decimal point is in a fixed point
The problem
Clearly with a limited number of places
after the decimal point it is far less
accurate as only a limited range of
decimals can be displayed
The number of extra places after the
decimal point increase accuracy
Fixed point example
1 byte = 8 bits
If 4 bits were assigned after the decimal
Place (this does not take up any bits)
8 4 2
0 1 1
1 . 1/2 1/4 1/8 1/16
1
0
1
0
1
Task
Look at the table on page 195 showing
binary fractions
Do questions 1-3 on page 196
So how do you represent all
of the other decimals in
binary?
Floating point binary
Floating Point Binary
In decimal, you can use scientific
notation for really big numbers
e.g. 1,2,0000,0000,0000
Would be
0.12 x 10
13
Exponent
Mantissa
Which holds the
digits
Which defines where to
place the decimal point
In this case move 13
places to the right
Floating Point Binary
Sign
bit
In binary, firstly bits are shared between the
mantissa and the exponent
In the example below, 2 bytes (16 bits) with
10 bits for the mantissa and 6 for the
exponent
Mantissa
Exponent
0110100000 000011
There is always
an imaginary
decimal here
= 0.1101 x 2
This is a sign bit – if positive i.e. 0 move the
decimal point right, if negative i.e. 1 move
the decimal point left
3
Floating Point Binary
Mantissa
Exponent
0110100000 000011
= 110.1
= 6.5 in denary
= 0.1101 x 2 3
Task
Do Q4 on page196
Rules:
1.
Place the point between the sign bit and the first
digit of the mantissa
2.
Convert the exponent to its decimal form (positive
or negative)
3.
Move the point right if the exponent is positive or
left if negative
4.
Convert the resulting binary number to denary
If the mantissa is
negative
Mantissa
1110100000
Negative
sign bit
Exponent
000011
Move three
places right
1.1101 would become 1110.1
Negative leftmost bit
-8 4 2 1 . ½
1 1 1 0 . 1
= -8+4+2+0.5 = -1.5
What if the mantissa and
exponent are negative?
Mantissa
1100000000
1.1
Exponent
111110
-2
Move the point left and fill with 1’s as
you do so:
1.111
-1+0.5+0.25+0.125 = -0.125
Task
Do question 5 on page 197
Normalisation
In order to get the most accurate representation
possible with a given size of mantissa, no zeros
should be put to the left of the most significant bit
(not including the sign bit)
E.g. in decimal:
0.034568x10 9 would be normalised to
0.34568x10 8
A binary number in normalised form will have the
first bit of the mantissa not including the sign bit as
a1
To normalise a number in
binary
0 000110101
1.
2.
3.
4.
000010
put in the binary point and convert the exponent to
decimal:
0.000110101 Exponent 2
Move the number to the correct position and count the
number of movements to the left to get the binary point
before the first 1
0.110101000 required 3 left places
Take 3 away from the exponent of 2: 2-3 = -1
Convert -1 back to binary
0 110101000
11111
To normalise a negative
number in binary
With a negative number, the
most significant bit not including
the sign bit will be a 0
Shift the number left until the
first bit (not the sign bit) is a
zero then adjust the exponent
To normalise a negative
number in binary
1 111100100
1.
2.
3.
4.
000011
put in the binary point and convert the exponent to
decimal:
1.111100100 Exponent 3
Move the number to the correct position and count the
number of movements to the left to get the binary point
before the first 0
1.001000000 required 4 left places
Take 4 away from the exponent of 3: 4-3 = -1
Convert -1 back to binary
1.001000000 11111
Task
Do question 6 and 7 on page 198
Read the hint on page 198
Do exercises on page 199