Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
C++: Convert Multibyte buffer to integer
Name: steve mcrae Date: May 15, 2002 at 16:51:23 Pacific
Comment:
I am developing in vc++ 7 (.net) and am having a brain fart.
I receie a byte buffer (bRecBuf) containing 00 64 90
The 90 referes to a success code so we can forget about the 3rd byte.
The first and second byte are a multibyte hex that needs to be converted to an integer.
so I have
bRecBuf[0]; // 0x00 bRecBuf[1]; // 0x64
and I need to convert it to integer 100
I can do this in my head but cant programatically? any help is appreciated/
Result = (int)bRecBuf[0] * 0x100 + (int)bRecBuf[1];
0
Response Number 2
Name: steve mcrae Date: May 15, 2002 at 17:30:51 Pacific
Reply:
Thanks Jim but sorry I was not clear.
The bytes in the buffer are hex code 0x00 and 0x64 and either can range from 0x00 to 0xFF. In this case 00 64 would translate to 100 and 00 01 would translate to 1. Thanks for the quick response.
> The bytes in the buffer are hex code 0x00 and 0x64 and either can range from 0x00 to 0xFF. In this case 00 64 would translate to 100 and 00 01 would translate to 1.
Yes. It's in "Hi-Lo" order. You have to take the first byte and multiply it by 256 (0x100) and add the second byte. If it were in "Lo-Hi" order, you could just typecast the whole thing as a word. 02 10 would translate into 528, right?
The (int) typecast will turn the byte into an integer. I expect your byte type is an unsigned char.
Summary: Hi Randy, Here is portion from one of my VB6 projects, where I m exporting data from SQL server to Excel and generating a Linemarker Chart for it. Hope this is helpful. I guess U can easily convert th...
Summary: here's my C coding problem: how does one convert a char array to an int array? for example, say if one has the pattern = "3 3 3 3 3 4" stored as chars in an array (with spaces) how can i convert this...
Summary: Hey. I need some help with C or C++. I have to import a file.txt with real E notated (like 2.3E-12) numbers in 2 columns in it (coordinates basicly - x and y) in to C or C++ (does not matter which, I...