Você está na página 1de 18

Binary Representation

Major: All Engineering Majors Major: All Engineering Majors


Authors: Autar Kaw, Matthew Emmons
http://numericalmethods.eng.usf.edu
Transforming Numerical Methods Education for STEM
2/10/2014 http://numericalmethods.eng.usf.edu 1
Transforming Numerical Methods Education for STEM
Undergraduates
Binary Representation
h // i l h d f d http://numericalmethods.eng.usf.edu
How a Decimal Number is How a Decimal Number is
Represented
2 1 0 1 2
10 6 10 7 10 7 10 5 10 2 76 257

+ + + + 10 6 10 7 10 7 10 5 10 2 76 . 257 + + + + =
http://numericalmethods.eng.usf.edu 3
Base 2
) 2 1 2 1 2 0 2 1 (
) 0011 1011 (
0 1 2 3

+ + +
=
1875 11
) 2 1 2 1 2 0 2 0 (
) 0011 . 1011 (
10
4 3 2 1
2
=

+ + + +
=

1875 . 11 =
http://numericalmethods.eng.usf.edu 4
Convert Base 10 Integer to Convert Base 10 Integer to
binary representation
Table 1 Converting a base-10 integer to binary representation.
Quotient Remainder
11/2 5
5/2 2
2/2 1
0
1 a =
1
1 a =
2
0 a =
2/2 1
1/2 0
2
0 a
3
1 a =
Hence
2
2 0 1 2 3 10
) 1011 (
) ( ) 11 (
=
= a a a a
http://numericalmethods.eng.usf.edu 5
2
) 1011 (
Start Start
Input (N)
10
Integer N to be
converted to binary
format
i = 0
Divide N by 2 to get
quotient Q & remainder R quotient Q & remainder R
a
i
= R
i=i+1,N=Q
Is Q = 0?
No
Yes
n = i
(N)
10
= (a
n
. . .a
0
)
2
http://numericalmethods.eng.usf.edu 6
STOP
Fractional Decimal Number
to Binary
T bl 2 C ti b 10 f ti t bi t ti
Number
Number after
decimal
Number before
decimal
Table 2. Converting a base-10 fraction to binary representation.
0.375 0.375
0.75 0.75
1.5 0.5
1 0 0 0
1
0

= a
2
0

= a
3
1

= a
1 a
2 1875 . 0
2 375 . 0
2 75 . 0
2 5 0
1.0 0.0
4
1

= a
Hence
) ( ) 1875 0 (
2 5 . 0
2
2 4 3 2 1 10
) 0011 . 0 (
) ( ) 1875 . 0 (
=
=

a a a a
http://numericalmethods.eng.usf.edu 7
Start
Input (F)
10
Fraction F to be
converted to binary
format
1 i
Multiply F by 2 to get
number before decimal,
S d ft d i l T
1 i =
S and after decimal, T
a
i
= R
T = = F 1, i i
Is T =0?
No
Y
n = i
(F)
10
= (a
-1
. . .a
-n
)
2
Yes
http://numericalmethods.eng.usf.edu 8
STOP
Decimal Number to Binary
( ) ( )
2
10
? . ? 1875 . 11 =
Since
2 10
) 1011 ( ) 11 ( =
and
Since
2 10
) 0011 . 0 ( ) 1875 . 0 ( =
and
we have
2 10
) 0011 . 1011 ( ) 1875 . 11 ( =
http://numericalmethods.eng.usf.edu 9
All Fractional Decimal Numbers
Cannot be Represented Exactly
T bl 3 C ti b 10 f ti t i t bi t ti
Number
Number
after
decimal
Number
before
Decimal
Table 3. Converting a base-10 fraction to approximate binary representation.
decimal Decimal
0.6 0.6
1.2 0.2
0.4 0.4
2 3 . 0
2 6 . 0
2 2 0
1
0

= a
2
1

= a
3
0 = a
0.4 0.4
0.8 0.8
1.6 0.6
2 2 . 0
2 4 . 0
2 8 . 0
3
4
0

= a
5
1

= a
28125 . 0 ) 01001 . 0 ( ) ( ) 3 . 0 (
2 2 5 4 3 2 1 10
= =

a a a a a
http://numericalmethods.eng.usf.edu 10
Another Way to Look at Another Way to Look at
Conversion
Convert to base 2
( )
10
1875 . 11
( )
1 3
3
10
1 2 2
3 2 11
+ + =
+ =
0 1 2 3
0 1 3
2 2 2
1 2 2
+ + =
+ +
( )
2
0 1 2 3
1011
2 1 2 1 2 0 2 1
=
+ + + =
http://numericalmethods.eng.usf.edu 11
( )
( )
4 3
3
10
0625 . 0 2 1875 . 0 + =

4 3 2 1
4 3
2 1 2 1 2 0 2 0
2 2
+ + + =
+ =


( )
2
0011 .
2 1 2 1 2 0 2 0
=
+ + + =
( ) ( )
2 10
0011 . 1011 1875 . 11 =
http://numericalmethods.eng.usf.edu 12
Additional Resources
For all resources on this topic such as digital audiovisual
lectures, primers, textbook chapters, multiple-choice
tests worksheets in MATLAB MATHEMATICA MathCad tests, worksheets in MATLAB, MATHEMATICA, MathCad
and MAPLE, blogs, related physical problems, please
visit
http://numericalmethods.eng.usf.edu/topics/binary_repr
esentation html esentation.html
Round off Error
Caused by representing a number Caused by representing a number
approximately
333333 . 0
3
1

3
... 4142 . 1 2
http://numericalmethods.eng.usf.edu 14
P bl t d b d ff Problems created by round off error
28 Americans were killed on February 25 28 Americans were killed on February 25,
1991 by an Iraqi Scud missile in Dhahran,
Saudi Arabia Saudi Arabia.
The patriot defense system failed to track
and intercept the Scud Why? and intercept the Scud. Why?
http://numericalmethods.eng.usf.edu 15
Clock cycle of 1/10 seconds was
represented in 24-bit fixed point represented in 24 bit fixed point
register created an error of 9.5 x
10
-8
seconds.
The battery was on for 100
consecutive hours, thus causing
an inaccuracy of
1hr
3600s
100hr
0.1s
s
10 9.5
8
=

http://numericalmethods.eng.usf.edu 16
1hr 0.1s
s 342 . 0 =
Problem (cont ) Problem (cont.)
The shift calculated in the ranging system The shift calculated in the ranging system
of the missile was 687 meters.
The target was considered to be out of The target was considered to be out of
range at a distance greater than 137
meters meters.
http://numericalmethods.eng.usf.edu 17
THE END
http://numericalmethods.eng.usf.edu

Você também pode gostar