Archived

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

Last Attacker

Float to Bin and Vise Versa

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 this post


Link to post
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 this post


Link to post
Share on other sites
Guest Anonymous Poster
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 this post


Link to post
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 this post


Link to post
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!

Share this post


Link to post
Share on other sites