I have a hex value stored in a two byte array:
unsigned char hex[2] = {0x02, 0x00};
How can I convert this to a decimal value?
I have a hex value stored in a two byte array:
unsigned char hex[2] = {0x02, 0x00};
How can I convert this to a decimal value?
Depends on endian-ness, but something like this?
short value = (hex[0] << 16) & hex[1];
This isn't an efficient way at least I do not think it is, but it would work in all situations regardless of size of the array and will easily convert to b.
__int8 p[] = {1, 1, 1, 1, 1}; //Let's say this was the array used.
int value = sizeof(p); //Just something to store the length.
memcpy(&value, &p, value > 4 ? 4 : value); //It's okay to go over 4, but might as well limit it.
In the above example it the variable "value" will have a value of 16,843,009. Which is equivalent to if you had done the below.
int value = p[0] | p[1] << 0x8 | p[2] << 0x10 | p[3] << 0x18;