#include
float hex_to_decimal(unsigned char *byte,int num)//十六進製製到浮點數
//
// float pfvalue=*(float*)&cbyte;
//return pfvalue;
return *((float*)byte);//方法二
}long floattohex(float hex)//浮點數到十六進製制轉換1
void floattobyte(float floatnum,unsigned char* bytearry)浮點數到十六進製制轉換2
}void main()
;//傳輸資料為3d cc cc cd
float hdecimal=0.0;
float flh=0.4;
// int num=sizeof(hexbyte);
// printf("num= %d\n",num);
hdecimal=hex_to_decimal(hexbyte,sizeof(hexbyte));//十六進製制轉換為浮點數
printf("\n 浮點數為:\n %f\n",hdecimal);
long hx=floattohex(hdecimal);//浮點數轉換為十六進製制一
printf("\n正序十六進製制值:\n %f=%x \n",hdecimal,hx);//正序顯示
floattobyte(hdecimal,floattohex);//浮點數轉為十六進製制二
printf("\n倒序十六進製制:\n%f=%x %x %x %x\n",hdecimal,floattohex[0],floattohex[1],floattohex[2],floattohex[3] );//倒序顯示
floattobyte(flh,floattohex);//浮點數轉為十六進製制二
printf("\n倒序十六進製制:\n%f=%x %x %x %x\n",flh,floattohex[0],floattohex[1],floattohex[2],floattohex[3] );//低位在前
floattobyte(flh,floattohex);//浮點數轉為十六進製制二
printf("\n正序十六進製制:\n%f=%x %x %x %x\n",flh,floattohex[3],floattohex[2],floattohex[1],floattohex[0] );//高位在前
}
float型別和16進製制資料轉換
先看一下ieee關於浮點數的定義 ieee 754規定了四種表示浮點數值的方式 單精確度 32位元 雙精確度 64位元 延伸單精確度 43位元以上,很少使用 與延伸雙精確度 79位元以上,通常以80位元實做 只有32位元模式有強制要求,其他都是選擇性的。32位單精度 單精度二進位制小數,使用32個位...
漢字與16進製制之間的轉換
從漢字轉換到16進製制 編碼,如 utf 8 gb2312 是否每字元用逗號分隔 public static string tohex string s,string charset,bool fenge system.text.encoding chs system.text.encoding.g...
python16進製制和10進製轉換
呼叫python內建int 函式把該字串轉為數字。以下為在python直譯器程式設計環境下的操作示範 呼叫python內建int 函式把該字串轉為數字。以下為在python直譯器程式設計環境下的操作示範 把十六進製制的字串轉為十進位制數字 python print int ff,16 255 把十進...