Re: converting to bits

From: Andreas Kahari (ak+usenet_at_freeshell.org)
Date: 11/12/03


Date: Wed, 12 Nov 2003 10:24:48 +0000 (UTC)

In article <3fb206c9$0$58712$e4fe514c@news.xs4all.nl>, Rick wrote:
> Hi,
>
> Does C have some handy functions to convert chars, ints and floats to bit
> arrays? I need to store that stuff binary so a few functions would be great.
> Converting chars and ints isn't difficult but floats are giving me a
> headache. And how about converting them back?
> I need a function like :
> <bitarray> convertFloatToBits( <number>, <signed or not>, <length
> default at 32 bits> )
> By the way, the C program has to be suitable for a microcontroller so I only
> have acces to the basic libraries.

If I'm not terribly wrong, most machines already store all
datatypes as binary.

If you calculate all the ones and zeroes of an integer or
floating point value, what type of array would you want to store
them in? An int array? That kind'a defeats the purpose of the
execise, don't you think?

Are you not happy with writing the floats and whatnot to a
binary file, or do you want to write character ones and charater
zeroes to a text file?

-- 
Andreas Kähäri


Relevant Pages

  • Re: What is this?
    ... Hence everything is 4-bytes: chars, ints, longs, floats... ...
    (comp.lang.c)
  • converting to bits
    ... Does C have some handy functions to convert chars, ints and floats to bit ... Converting chars and ints isn't difficult but floats are giving me a ...
    (comp.lang.c)
  • Re: fgets problem
    ... int main ... And then you're putting floats into your array of floats. ... And you're looping back to write more chars into your array of floats. ...
    (comp.lang.c)
  • Re: What is this?
    ... everything is 4-bytes: chars, ints, longs, floats... ...
    (comp.lang.c)
  • Re: RAD vs. performance
    ... Which is ok because ints and floats have different semantics anyway. ... largely dynamic typing, and prototype-oo integrated fairly deeply into the ...
    (comp.lang.misc)