I have a file I am trying to decode and the size of the portion of the file I need is specified by 3 bytes in its header. How can I convert these 3 separate bytes into 1 single integer?
Thanks for any help you have.
Printable View
I have a file I am trying to decode and the size of the portion of the file I need is specified by 3 bytes in its header. How can I convert these 3 separate bytes into 1 single integer?
Thanks for any help you have.
What, exactly, does each of the bytes represent? Are they part of a single 24 bit integer?
Viggy
Yes they are part of a single 24 bit integer, but I can't figure out how to get the program to recognize them as a single integer, and not 3 different bytes in an array...Quote:
Originally Posted by MrViggy
I don't know how to create a 24-bit integer, but if it were a 32-bit integer conversion would look something like this, where buffer contains the binary representation of a 4-byte integer. I assume a 24-bit integer would be similar. I know short = 16 bit integer, long = 32 bit. I don't know what is a 24 bit. Yes, I know those sizes are not guarenteed, but that's what they are on 16 and 32 bit operating systems such as MS-DOS, MS-Windows and *nix.
Code:int n = *(int *)buffer;
Is this not a possible solution
I have assumed that arr[2] is the MSB and arr[0] is LSB.Code:BYTE arr[3] = {0x23, 0x45, 0x67};
UINT val = arr[2] << 16 | arr[1] << 8 | arr[0];
Thanks for the help it worked perfectly!
anyone know how to do this in .net?