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.

Recommended Answers

All 4 Replies

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.

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

0.25 = 0x3e800000
0.01 = 0x3c23d79a = 0.0099999998

Or fixed point BCD (2 places)
0.25
0x0000000025

Hey thanks mate this has helped a great deal! +rep

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.