Combine hex numbers in C code

April 28, 2013 at 05:27:36
Specs: Linux
int32_t chout;
unsigned char parameter[] = {0x01, 0x04, 0x00, 0x00, 0x00, 0x02, 0x71, 0xCB};
write(mainfd, parameter, sizeof(parameter)); //Send data
int i
for(i = 0; i < 3; i++) {
read(mainfd, &chout, sizeof(chout)); /* Read hex from device */
if (chout != 0) {
printf("Received %08X\n", chout);
chout = 0;

This is the output when the code is run
Received 43040401
Received 48B9096E
Received 0000003F

Actual number wanted 010404436E09B9483F
It is a reverse of the 3 hex numbers above.

I have the above C code which sends the unsigned char parameter[] request to a device which sends back a reply within the FOR loop above. I have become stuck in trying to combine the 3 received hex numbers into the actual number wanted. I then need to extract certain portions of the actual number to derive a decimal number but that is for another day. Can someone please point me in the right direction, any guidance is appreciated. I'm running this on Linux and am new to C code.

See More: Combine hex numbers in C code

Report •

Report •

May 2, 2013 at 01:55:26
Thanks Razor2.3, lots learnt, have nearly answered my own question. Cheers

Report •
Related Solutions

Ask Question