Re: beginner question about storing binary data in buffers, seeing
binary data in a variable, etc
* darren:
Im working on an assignment that has me store data in a buffer to be
sent over the network. I'm ignorant about how C++ stores data in an
array, and types in general.
A textbook would be good resource.
If i declare an array of chars that is say 10 bytes long:
char buff[10];
does this mean that i can safely store 80 bits of data?
Yes.
When i think of an array of chars, i think each spot in the array as a
sequence of 8 1's or 0's. Is this a correct visualization?
No. A byte can be more than 8 bits. The number of bits per byte for a given C
or C++ implementation is CHAR_BIT, from <stddef.h>.
I guess
my question here is why do most buffers seem to be implemented as char
arrays?
Are they?
Can any binary value between 0 and 255 be safely put into a
char array slot (00000000 to 11111111).
It depends what you're really asking.
If you provided a concrete example and what you expected as result, one could
say whether that was correct or not.
But a char has guranteed at least 256 possible bitpatterns (minimum 8 bits), yes.
Why not implement a buffer using uint8_t ?
That's not presently a standard C++ type.
Obviously I have a very loose grasp on how buffers are saving data,
and how a receiver gets this data on their end. I understand the
sockets stuff, just not the buffer-specific stuff. Any enlightenment
would be most appreciated.
See above.
Cheers, & hth.,
- Alf
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?