question about converting base 10 to binary

Discussion in 'Homework Help' started by fishguts, Oct 16, 2007.

1. fishguts Thread Starter Member

Sep 3, 2007
22
0
Hello I have one question. We have started to learn how to convert decimal to binary and most of it is easy except one problem i have. I need to convert 22.5625 into decimal. I can convert 22 fine but its the .5625 that I do not know how to deal with. Can anyone point me in the right direction. Thanks

2. Papabravo Expert

Feb 24, 2006
12,285
2,724
To the left of the binary point you have positive powers of 2. To the right of the binary point you have neagative powers of 2. The first position to the right of the binary point represents 1/2 or 0.500. Subtracting that from, .5625 leaves 0.0625 which all us mechanics and builders recognize as the decimal equivalent of 1/16 or 2^-4. So

0.5625(base 10) = 0.1001(base 2)

Get the picture?

3. arthur92710 Active Member

Jun 25, 2007
307
1
its already decimal. so, you mean to binary. and decimals don't always go perfectly into binary.
like 1.1234 = 1.000111111
but .000111111=.12304

4. beenthere Retired Moderator

Apr 20, 2004
15,808
295
You may recall a model of Pentium computer that had some problems with binary - decimal conversions.

5. bloguetronica AAC Fanatic!

Apr 27, 2007
1,359
26
I think it was the Pentium 486 that had problems with floating point numbers.

6. arthur92710 Active Member

Jun 25, 2007
307
1
lol and people bought it?

7. JoeJester AAC Fanatic!

Apr 26, 2005
4,074
1,776
I don't believe there was a Pentium 486. I recall the Intel 486 having problems that were resolved in the Pentium I.

8. GS3 AAC Fanatic!

Sep 21, 2007
408
35
I have spent a bit of time giving this some thought and here are my conclusions:

- The integral part of a decimal number will always be represented by an integral binary (with no fractional part) while the fractional part of a decimal number will always be represented by a fractional part of a binary number (with no integral part). An integral number will be integral in any integral base and a fractional number will be fractional in any integral base. This means we can split a decimal number into its integral and fractional parts, convert them separately to binary and add them up again in binary. This means we can forget about the integral part and concentrate on converting the fractional part.

- Some decimal fractions may convert into binary exactly (like .5625) but others may not (like .5624) and we may get an infinite number of binary digits in the binary fraction.

- One way of converting a decimal fraction to binary fraction is to first multiply it by a power of 2, then convert to binary and then divide by the same power of 2 (which just means displacing the binary point to the left).

Examples:

- Convert .5625 to binary.
- Multiply .5625 * 2^4 = 9
- Convert 9 to binary = 1001
- Divide 1001 / 2^4 = .1001

- Convert .5625 to binary
- Multiply .5625 * 2^10 = 576
- Convert 576 to binary = 1001000000
- Divide 1001000000 / 2^10 = .1001000000
(Same thing, more precision)

- Convert .5624 to binary
- Multiply .5624 * 2^20 = 589719.1424
- Convert 589719 to binary = 10001111111110010111
- Divide 10001111111110010111 / 2^20 = .10001111111110010111
- (The more precision you want, the higher the power of 2 to use. Use the same power as the number of significant digits you want in the result.)

- Convert 165650.435 to binary
- 165650 = 101000011100010010
- Multiply .435 by 2^20 = 456130.56
- Convert 456131 to binary: 1101111010111000010
- Divide by 2^20: .01101111010111000010
- We now add integral and fractional parts:
The answer is 101000011100010010.01101111010111000010
which we can round off to:
101000011100010010.01101111010111
Converting this back to decimal we get
165650.43499755859375

Roughly three decimal digits are equivalent in precision to 10 binary digits so, if we truncate to ten fractional digits we get.
101000011100010010.0110111101 = 165650.4345703125

So it is a good rule of thumb to use 10 binary digits for every 3 decimal digits.

(I hope not too many mistakes crept in all the foregoing.)

9. fishguts Thread Starter Member

Sep 3, 2007
22
0
thanks for the help!

10. Salgat Active Member

Dec 23, 2006
215
1
http://en.wikipedia.org/wiki/Pentium_FDIV_bug

Oh gosh, thanks for reminding me of that 11. ambreen New Member

Mar 5, 2008
6
0
no actually i want to generate binary seq. of 10^5 bits based on distribution by lempel-ziv algorithim using Matlab.I need to write code for its phrasing & codwords in dictionary contents & then for compression rate using matlab it should run

12. Dave Retired Moderator

Nov 17, 2003
6,960
172
Please do not litter the forums with requests for help with the same question. Keep this in your active thread.

Thank you.

Dave