0% found this document useful (0 votes)
9 views

Decimal 2 Binary

This document provides instructions for converting a decimal number to its binary representation. It explains that you repeatedly subtract the highest power of two that is less than the remaining portion of the number until reaching zero. An example converts -2.75 to binary. Exercises at the end ask the reader to represent given numbers using a specified floating point system, identifying overflows or underflows.

Uploaded by

Muhammad Shujan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Decimal 2 Binary

This document provides instructions for converting a decimal number to its binary representation. It explains that you repeatedly subtract the highest power of two that is less than the remaining portion of the number until reaching zero. An example converts -2.75 to binary. Exercises at the end ask the reader to represent given numbers using a specified floating point system, identifying overflows or underflows.

Uploaded by

Muhammad Shujan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

August 27, 2015

Math 5630/6630
Decimal to Binary (Nothing to it!)
How would you go about representing a number x R in binary? We want
to have it in the form


d1 d2
x = (d0 .d1 d2 . . .)2 2e = d0 +
+ 2 + . . . 2e ,
2
2
for some integer e and digits di {0, 1}. Multiplying 2e into the sum gives
us
x = (d0 2e + d1 2e1 + d2 2e2 + . . .).
For now, assume x > 0 (we can always fix the sign later). To write x in
binary, all we need to do is
1. Find the highest power e of two so that 2e x. Subtract it from x to
form x1 = x 2e .
2. Now find the highest power of two that is smaller than x1 , then subtract it from x1 to form x2 .
3. Continue until you get 0 (youre done). If the floating point system
has finite accuracy, you may need to round/chop (maybe x has an
infinite binary expansion).
Example: x = 2.75.
1. First forget about the minus sign. Then we have 2.75.
2. 21 is the highest power of two less than 2.75. When we subtract it,
0.75 remains.
3. 20 > 0.75 is too big, but 21 = 0.5 is the next power and this one
works 21 < 0.75. Subtract it, 0.25 remains.
4. Next is 22 , which is exactly 0.25. Done!
So
2.75 = 1 21 + 0 20 + 1 21 + 1 22 .
To normalize, factor out the highest power of 2, i.e. 21 , which gives us


0
1
1
2.75 = 1 + + 2 + 3 21 .
2 2
2
Or in binary form: 2.75 = (1.0.11)2 21 .
1

Exercises:
Consider the normalized floating point system (2, 4, 2, 3), where the floating point approximation f l(x) of x is achieved by means of chopping. Represent the following numbers in this system. If the magnitude of the number
is bigger than the maximum floating point number, call it inf. If its
magnitude is smaller than the smallest positive number, call it 0.
1. x = 7.5
2. x = 20
3. x = = 3.14159265359 . . .

You might also like