APS
APS

Reputation: 59

How to merge 4 unsigned char array elements in one hex value?

I have an array of 4 elements of type unsigned char. How to merge these in one hex value? I need to convert this value to IEE754 value.

e.g. unsigned char arr[]={0x41,0xD9,0xD4,0x03}

expected o/p : 0x41D9D403

Upvotes: 1

Views: 865

Answers (1)

sri
sri

Reputation: 357

unsigned long hex_val = ((unsigned long)arr[0] << 24) | ((unsigned long)arr[1] << 16) | ((unsigned long)arr[2] << 8) | ((unsigned long)arr[3]);

Upvotes: 1

Related Questions