#### Archived

This topic is now archived and is closed to further replies.

# Float to Bin and Vise Versa

This topic is 5492 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey all, I''m writing a VB app. (a calculator) that can convert between Decimal, Hex, Oct and Binary with the 4 data-types : Byte, Short, Long and Float. You can also perform basic calculations such as Addition, OR operation, etc. Everything works except the float convertion. Can someone please send me an algorithm that can convert from a floating-decimal to a 4-byte binary. I know how it works but sometimes you have to add a 1, why?. I don''t know. Also can someone please tell me how to convert back to decimal. Thanks! ----------=Last Attacker=---------- ICQ: 120585863 E-mail: laextr@icqmail.com

##### Share on other sites
Well, you can''t really convert a number with a decimal in it to binary. Or are you just throwing out anything after the decimal?

##### Share on other sites
http://www.mimosa.org/ftpdown/ieeefp.pdf

The link explains the IEEE floating point format. You probably already have similar info but just in case you don''t...

##### Share on other sites
quote:
Original post by Sirveaux
Well, you can''t really convert a number with a decimal in it to binary.
1.12510 = 1.0012
I''m not seeing the problem here.

##### Share on other sites
binary can do decimals EASILY, its just damn near impossible to represent like .3 or .7 (well... if i remember right those two in particular... i think) and a few other numbers, each radix has some fractions that are not easily displayed (decimal has them, 1/3* comes to mind). but it IS possible to more or less display something really close to any fraction in any radix. so BAH. beer hunter has it right tho, no problem seen =P

*1/3 can be represented easily in base 3 =P
0.333333333(10) = 0.1(3)
hehehe

Bungo!

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 17
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631759
• Total Posts
3002162
×