|
-
November 29th, 2005, 04:31 PM
#1
Convert a 3-byte array into a single size integer?
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.
-
November 29th, 2005, 05:27 PM
#2
Re: Convert a 3-byte array into a single size integer?
What, exactly, does each of the bytes represent? Are they part of a single 24 bit integer?
Viggy
-
November 29th, 2005, 07:27 PM
#3
Re: Convert a 3-byte array into a single size integer?
 Originally Posted by MrViggy
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...
-
November 29th, 2005, 10:22 PM
#4
Re: Convert a 3-byte array into a single size integer?
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;
-
November 30th, 2005, 12:08 AM
#5
Re: Convert a 3-byte array into a single size integer?
Is this not a possible solution
Code:
BYTE arr[3] = {0x23, 0x45, 0x67};
UINT val = arr[2] << 16 | arr[1] << 8 | arr[0];
I have assumed that arr[2] is the MSB and arr[0] is LSB.
-
December 1st, 2005, 08:07 PM
#6
Re: Convert a 3-byte array into a single size integer?
Thanks for the help it worked perfectly!
-
January 29th, 2009, 11:47 AM
#7
Re: Convert a 3-byte array into a single size integer?
anyone know how to do this in .net?
-
January 29th, 2009, 12:46 PM
#8
Re: Convert a 3-byte array into a single size integer?
 Originally Posted by DaBoonDockSaint
anyone know how to do this in .net?
Yes, in the exact same way. What does using .Net have to do with anything if it is a c++ program? You still have the same problem and the same kind of solution.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|