I have a string of 256*4 bytes of data. These 256* 4 bytes need to be converted into 256 unsigned integers. The order in which they come is little endian, i.e. the first four bytes in the string are the little endian representation of the first integer, the next 4 bytes are the little endian representation of the next integer, and so on.
What is the best way to parse through this data and merge these bytes into unsigned integers? I know I have to use bitshift operators but I don't know in what way.
byte0 | (byte1 << CHAR_BIT) | (byte2 << 2 * CHAR_BIT) | (byte3 << 3 * CHAR_BIT)
... – Krissie<cstddef>
which expands to the number of bits in a byte on your platform. – Krissiechar
is always a byte. It's just that they need not be 8 bits long. You are confusing "byte" with "octet". – Krissieunsigned char << int
, the char is promoted (implicitly converted) tounsigned int
(or is itint
? Somebody who speaks C++ better, please confirm this!), so you will be getting the expected result. – Krissie