Binary Representation
Download
Report
Transcript Binary Representation
Binary Representation
Major: All Engineering Majors
Authors: Autar Kaw, Matthew Emmons
http://numericalmethods.eng.usf.edu
Transforming Numerical Methods Education for STEM
Undergraduates
4/1/2016
http://numericalmethods.eng.usf.edu
1
Binary Representation
http://numericalmethods.eng.usf.edu
How a Decimal Number is
Represented
257.76 2 10 2 5 101 7 100 7 10 1 6 10 2
3
http://numericalmethods.eng.usf.edu
Base 2
(1 23 0 2 2 1 21 1 20 )
(1011.0011) 2
1
2
3
4
(
0
2
0
2
1
2
1
2
) 10
11.1875
4
http://numericalmethods.eng.usf.edu
Convert Base 10 Integer to
binary representation
Table 1 Converting a base-10 integer to binary representation.
Quotient
11/2
5
5/2
2
2/2
1
1/2
0
Remainder
1 a0
1 a1
0 a2
1 a3
Hence
(11)10 (a3 a 2 a1a0 ) 2
(1011) 2
5
http://numericalmethods.eng.usf.edu
Start
Input (N)10
Integer N to be
converted to binary
format
i=0
Divide N by 2 to get
quotient Q & remainder R
i=i+1,N=Q
ai = R
No
Is Q = 0?
Yes
n=i
(N)10 = (an. . .a0)2
STOP
6
http://numericalmethods.eng.usf.edu
Fractional Decimal Number
to Binary
Table 2. Converting a base-10 fraction to binary representation.
0.1875 2
0.375 2
0.75 2
0.5 2
Number
Number after
decimal
0.375
0.75
1.5
1.0
0.375
0.75
0.5
0.0
Number before
decimal
0 a1
0 a2
1 a 3
1 a4
Hence
(0.1875)10 (a1a 2 a 3a 4 ) 2
(0.0011) 2
7
http://numericalmethods.eng.usf.edu
Start
Fraction
F
to
be
converted to binary
format
Input (F)10
i 1
Multiply F by 2 to get
number before decimal,
S and after decimal, T
i i 1, F T
ai = R
No
Is T =0?
Yes
n=i
(F)10 = (a-1. . .a-n)2
STOP
8
http://numericalmethods.eng.usf.edu
Decimal Number to Binary
11.187510
?.?
2
Since
(11)10 (1011) 2
and
(0.1875)10 (0.0011) 2
we have
(11.1875)10 (1011.0011) 2
9
http://numericalmethods.eng.usf.edu
All Fractional Decimal Numbers
Cannot be Represented Exactly
Table 3. Converting a base-10 fraction to approximate binary representation.
Number
0.3 2
0.6 2
0.2 2
0.4 2
0.8 2
0.6
1.2
0.4
0.8
1.6
Number
after
decimal
0.6
0.2
0.4
0.8
0.6
Number
before
Decimal
0 a1
1 a2
0 a3
0 a4
1 a 5
(0.3)10 (a1a2 a3a4 a5 ) 2 (0.01001) 2 0.28125
10
http://numericalmethods.eng.usf.edu
Another Way to Look at
Conversion
Convert 11.187510 to base 2
1110 23 3
23 21 1
2 2 2
3
1
0
1 2 0 2 1 2 1 2
10112
3
11
2
1
0
http://numericalmethods.eng.usf.edu
0.187510 23 0.0625
2 3 2 4
1
2
3
0 2 0 2 1 2 1 2
4
.00112
11.187510 1011.00112
12
http://numericalmethods.eng.usf.edu
Additional Resources
For all resources on this topic such as digital audiovisual
lectures, primers, textbook chapters, multiple-choice
tests, worksheets in MATLAB, MATHEMATICA, MathCad
and MAPLE, blogs, related physical problems, please
visit
http://numericalmethods.eng.usf.edu/topics/binary_repr
esentation.html
THE END
http://numericalmethods.eng.usf.edu