I am using Microsoft Visual C++ 2008. My program reads the two bytes from the file, and I want to store them in a int variable as a one number like 1B6A. How can I combine the values of the two bytes into one number? I need to turn 1B and 6A into 1B6A.
NOTE: I need a code that works with any hexadecimals from 00 to FF, not just the two I mentioned above (the code needs to work with any combinations of bytes).
// assume the two bytes you are reading is stored in array named "b"
unsignedchar b[2] = { 0x1B,0x6A};
unsignedint var=0;
var = b[1];
var = var | (b[0] << 8);
Thank you very much for the code. It works and I found it really useful. I sent this reply a little bit late because I had to change my code a little, so I can fit your code inside to test it. Thank you very much.