DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Computer Science (http://www.daniweb.com/forums/forum14.html)
-   -   Binary (http://www.daniweb.com/forums/thread201044.html)

Stemack Jun 30th, 2009 1:42 pm
Binary
 
Sorry in advance if this is in the wrong forums but I am new here and was not too sure where to post for help. Onto business I was wondering if anybody knows how to convert a number that has a decimal point in it (example: 0.31) into binary? I have been tasked to do it but everywhere I look is no help and was wondering if anybody here could shed some light onto this?

Thanks in advance,
Steve.

wildgoose Jul 1st, 2009 8:48 pm
Re: Binary
 
You are talking about floating point.
Dependent upon the data format typically IEEE
32-bit SPFP Single-Precision Floating-Point
64-bit DPFP Double-Precision Floating-Point
80-bit Double-Extended Precision Floating-Point

there are three components.
A sign bit, typically the MSB.
The Exponent
and
the Mantissa.
So 1.0 in 32-bit using IEEE would be
0x3f800000
-1.0
0xbf800000

32-bit SPFP
Sign:{31} Exponent:{30...23} mantissa:{22...0}
64-bit DPFP
63 62...52 51....0
80-bit
79 78...64 62....0
There's an implied (1) bit at bit 63.

Deque Jul 2nd, 2009 3:56 am
Re: Binary
 
e.g.: 0.25
0.25 * 2 = 0.5 --> 0*2^(-1)
0.5 * 2 = 1.0 --> 1*2^(-2)
--> (0.25)decimal = (0.01)binary

wildgoose Jul 2nd, 2009 4:04 am
Re: Binary
 
0.25 = 0x3e800000
0.01 = 0x3c23d79a = 0.0099999998

Or fixed point BCD (2 places)
0.25
0x0000000025

Stemack Jul 2nd, 2009 8:10 am
Re: Binary
 
Hey thanks mate this has helped a great deal! +rep


All times are GMT -4. The time now is 5:32 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC