"Speed" <lo**********@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
Hi,
I have a 57000 bit long binary number and I want to save it to a file.
At the moment I am using an unsigned char array to store the array and
then fwrite to store it as follows.
fwrite( BinArr, sizeof(unsigned char), 57000, BinFile);
But it is a waste of space as this takes up around 57 KB which if I
could store as bits would only take up around 7 KB.
Could you please tell me if this could be done.
Thanks a ton.
Speed.
Sure, just store the bytes as you're using them. You say it's a "binary
number". How is it stored in variables? BCD (Binary Coded Decimal)? Some
other representation? How much memory does it take to store them in the
program?
You say you have a "57000 *bit* long binary number*. Is it 57,000 bits or
digits? If it's 57000 bits, then just store them as binary.
unsigned BinArr char[57000 / sizeof( unsigned char )]; // this would be
57,000 *bits*
// This array is loaded/used somewhere, or how are you using these 57,000
bits?
fwrite( BinArr, sizeof( unsigned char), 57000 / sizeof( unsigned char),
BinFile );
57000 / 8 (sizeof unsigned char on my system) is 7125, so these 57000 bits
are stored in 7125 bytes.