Why not read 128 bits and mask out the unwanted data.
gerard4143
Nearly a Posting Maven
2,272 posts since Jan 2008
Reputation Points: 512
Solved Threads: 387
Well if I had to do this I would create an array like(this assumes 64 bit longs)
unsigned long mya[2] = {0,0};/*128 bits initialized to zero*/
and read the data like so
fread(mya, sizeof(unsigned long), 2, fileStream);/*read 128 bits*/
gerard4143
Nearly a Posting Maven
2,272 posts since Jan 2008
Reputation Points: 512
Solved Threads: 387
you could create an 18-byte character array, assuming 8 bits to the byte. Files do not contain bits -- they contain bytes, and the number of bits to the byte is operating system dependent. On MS-Windows and *nix there's 8 bit to the byte. So 128 bits would be 128/8 = 18 bytes.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
you could create an 18-byte character array, assuming 8 bits to the byte. Files do not contain bits -- they contain bytes, and the number of bits to the byte is operating system dependent. On MS-Windows and *nix there's 8 bit to the byte. So 128 bits would be 128/8 = 18 bytes.
That's odd, I always thought byte size was a feature of the hardware and not the operating system.
gerard4143
Nearly a Posting Maven
2,272 posts since Jan 2008
Reputation Points: 512
Solved Threads: 387
You are right. The number of bits in a byte is hardware dependent.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
>>I was under the impression that 8bits = 1byte is a universally accepted measurement,
Nope -- there are 4 and 7 bit byte hardware, but 8 bit is probably the most common.
>>But I want to read bits.
Impossible. You have to read bytes and then extract bits in memory.
>>This is exactly why I'm looking for a system that does not involve more than one variable to hold the data
You won't find it on MS-Windows, MS-DOS, or *nix systems because they have not invented those things yet. You might try IBM mainframe -- but you may have to pay a few million dollars to get it.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
Right. But I want to read bits. You see, my task is to develop some kind of a crypto system which means I got to do a lot of bit substitutions and permutations in which case I certainly have to mask bits out.
You can't read bits outright, the hardware can only address bytes. If you need to interrogate bits, you must rely on masking operations or bit operators.
gerard4143
Nearly a Posting Maven
2,272 posts since Jan 2008
Reputation Points: 512
Solved Threads: 387
Read this wiki article . I have never actuall come across such a hardware myself, at least not that I know of.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343