http://www.velocityreviews.com/forums/(E-Mail Removed) (Helen) wrote:

# Hello

#

# I have one float a

# I am trying to write a into a file but only use

# n bits for that, what's the best way to do

# for example

#

# a=0.391790

#

# I am trying to use 8 bits for that.

You can try something like

int exp; int fraction = (int)(MAX*frexp(number,&exp));

Then

number =approx= scalb((double)fraction/MAX,exp)

If you want to pack it into that 3 bits exponent + 5 bits fraction, you can have

something like

enum {MAX=32};

...

int packed = (exp&7)<<5 | fraction;

--

Derk Gwen

http://derkgwen.250free.com/html/index.html
I love the smell of commerce in the morning.