Quick Question: How to transform bytes in integers?
Hello...
Well, I have an array of bytes loaded from a bmp file, and I want to stract the width. However, the width is stored in the 18, 19, 20 and 21 elements of the array. So, if I read the array[18], it will return 0, but the actually width is 256, and it is stored in both array[18] and array[19] (I really don't know how this dword thing works). Now, how can I get this in an integer value? I would apreciate any help you coud give me.
Thanks a lot!
[edited by - algumacoisaqualquer on July 27, 2002 8:26:10 AM]
Use the structures provided in the windows headers, look up
codeka.com - Just click it.
BITMAPFILEHEADER
, BITMAPINFO
and BITMAPINFOHEADER
in MSDN. These will make your life much easier. codeka.com - Just click it.
In general you can something like this:
-Neophyte
unsigned char bytearray[ARRAY_SIZE];int someint = *(int*)&bytearray[index_of_first_byte_of_int];// In your case, with the int stored at bytes 18-21, you can:int width = *(int*)&array[18];// Or, in the C++ way:int width = *static_cast<int*>(&array[18]);
-Neophyte
You''d want
codeka.com - Just click it.
reinterpret_cast
in this case, not static_cast
. static_cast
is used when you want data conversion to happen (like casting a float to an int, for example). Though in this case, they would probably both produce the same output. codeka.com - Just click it.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement