Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: float saving using only N bits

Thread Tools

Re: float saving using only N bits

Derk Gwen
Posts: n/a
      06-30-2003 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));
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
I love the smell of commerce in the morning.
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
float to string to float, with first float == second float Carsten Fuchs C++ 45 10-08-2009 09:47 AM
8-Bits vs 12 or 16 bits/pixel; When does more than 8 bits count ? Al Dykes Digital Photography 3 12-29-2003 07:08 PM
Re: float->byte->float is same with original float image. why float->ubyte->float is different??? bd C Programming 0 07-07-2003 12:09 AM
Re: float saving using only N bits Ben Pfaff C Programming 1 06-29-2003 08:32 PM
Re: float saving using only N bits Tom St Denis C Programming 0 06-29-2003 04:33 PM