Click to See Complete Forum and Search --> : How to: convert float to DWORD etc.


MeierD
May 31st, 1999, 12:41 AM
Hi,

Is there anyone who has a C++ - class with conversionmethods like:

- convert float to DWORD and reverse
- convert float to a high and a low word and reverse
- convert double to two DWORD's and reverse
- convert double to four words and reverse
- convert dezimal to hex and reverse
- convert dezimal to octal and reverse
- convert dezimal to bitstring and reverse

or is there a class like this on the web ?


Thanks for your answers.


Regards,

Daniel

ilian
May 31st, 1999, 01:16 AM
Hi,
I have no such a class, but it is pretty easy to write your own. If you need help for this, write me.
(Sorry for my bad Endglish!)

MeierD
May 31st, 1999, 01:29 AM
Hi iliani,

I only know, that the conversion from float to bitstream (or high and low word)
has a norm at IEEE. Could you explain, how you would write a method to
convert float to high and low words ?
And the same from double to four words ?

Thanks for your help.

Regards,
Daniel

MeierD
May 31st, 1999, 01:53 AM
I only know that the bitstream is organized in:

for float single format:
--------------------------------------------------------
<s> <exponent> <significand>
¦ ¦ ¦
1 bit 8 bit 23 bit = 32 bit (DWORD)

And the formula is: X = (-1)^s * 2^(exponent - 127) * (1.significand)

s = sign bit = bit string of length one.
exponent = biased exponent = bit string of length 8.
significand = bit string of length 23 encoding the number's
significant bits that follow the binary point,
yielding a 24 bit significand digit field
for the number that always begins "1.____".


for double format:
--------------------------------------------------------
<s> <exponent> <significand>
¦ ¦ ¦
1 bit 11 bit 52 bit = 64 bit (HIGH DWORD + LOW DWORD)

And the formula is: X = (-1)^s * 2^(exponent - 1023) * (1.significand)

s = sign bit = bit string of length one.
exponent = biased exponent = bit string of length 11.
significand = bit string of length 52 encoding the number's
significant bits that follow the binary point,
yielding a 53 bit significand digit field
for the number that always begins "1.____".



I only have an interface of word and I has to transfer the resulting
DWORD's with shift operations to high and low words.


Thanks for your interest and help.

Regards,

Daniel