1、十六进制hex转换为整型

//int is 4 char，need the input is array with four hex；
int char4_int(unsigned char* pData)
{
int t = 0;
for (int i = 0; i < 4; i++){
t = t << 8 | pData[i];
}
return t;
}

//long int is 8 char，need the input is array with eight hex；
long int char8_int(unsigned char* pData)
{
long int t = 0;
for (int i = 0; i < 8; i++){
t = t << 8 | pData[i];
}
return t;
}

2、8个hex转换为一个double

double char8_double(unsigned char* pData)
{
char bin[64];
for(int i = 0; i < 8; i++){
unsigned char GetBit = 0x80;
for (int j = 0; j < 8; j++){
if (GetBit & pData[i]){
bin[i * 8 + j] = 1;
}
else
bin[i * 8 + j] = 0;
GetBit = GetBit >> 1;
}
}
return BinaryToDouble2(bin);
}
double BinaryToDouble2(char *bina){
int i, j, expo = 0;
double sum = 0, sum2 = 0;
for (i = 11; i > 0; i--){
expo += (bina[i] * power(2, 11 - i));
}
expo -= 1023;//指数=阶码减去1023！

bina[11] = 1;
j = expo + 1;//
for (i = 11; i < 64; i++){
sum2 += (bina[i] * power(2, --j));
}
/*
for (i = 11 + expo; i < 64; i++){
sum += bina[i] * (1.0 / power(2, i - 10 - expo));
}*/

if (bina[0] == 1){
return (-(sum2 + sum + 0.0000001));
}
else{
return (sum2 + sum + 0.0000001);
}
}

//function: base^index
double power(int base, int index){
double value = 1.0;
int count;
if (index == 0){
value = 1;
}
else if (index<0){
index = -index;
for (count = 1; count <= index; count++){
value *= base;
}
value = 1.0 / value;
}
else if (index>0){
for (count = 1; count <= index; count++){
value *= base;
}
}
return value;
}