I've come across a little problem in a program I'm writing. I need to read data from a file with the following size blocks/chunks:
8bits, 24bits, 16bits, 16bits, 16bits... 32bits
At the moment I'm reading the data from the document using istream::read() and storing it as a char array of either 1, 2, 3 or 4 bytes long, however I'm unsure of how to manipulate the data as a whole block.
From looking around the internet I've found references to bitwise operations but don't exactly know if I'm doing the right thing.
I have tried: short variable = (variableArrayWhereItIsStored[0] << 8 ) | variableArrayWhereItIsStored[1]
however from the output of printf("%hu", variable) I don't think this is giving me the intended results.
Can anyone see where I'm going wrong or suggest other ways of doing it?
Any help is greatly appreciated :)
Hey, i'm marking this topic as closed, sorry for being a little lazy...
one thing to note for anyone else with this problem: MAKE SURE THE VARIABLE YOU'RE SHIFTING IS UNSIGNED! haha i found that one out the hard way, its why the values were crazy-big... >_<