//------------------------------------------------------------------------------------------------------------------------------------------//
windows ----GPS
#include//联合fnum存储数据 union fnum { int m; float f; }; int main(int argc, char *argv[]) { union fnum num; num.m=0x40a80000;//赋值给整数 printf("十六进制输出int:0x%x\n",num.m);//输出0x40a80000 printf("十进制输出float:%f\n",num.f);//输出5.250000 return 0; }
//-------------------------------------------------------------------------------------------------------------------------------------//
#include <stdio.h>
int main(){ long int n; //Tc3.0ºÃÏñÊÇ16λ±àÒëÆ÷ printf("ÊäÈë8λ16œøÖÆÊý£º"); scanf("%x",&n); printf("%f\n",*((float*)&n)); return 0; }
//--------------------------------------------------------------------------------------------------------------------------------------------//
2)
#include<stdio.h>
int main(){ long int n; //Tc3.0ºÃÏñÊÇ16λ±àÒëÆ÷ printf("ÊäÈë8λ16œøÖÆÊý£º"); scanf("%x",&n); printf("%f\n",*((float*)&n)); return 0; }//---------------------------------------------------------------------------------------------------------------------------------------------------//
3)
#include <stdio.h>
int main(void){ float a=0.0f; unsigned char * b = (unsigned char*)&a; char c[4] = {0x4B,0xDA,0x74,0x0C}; int i = 0; printf("b1:%d\n",b); for(i = 0; i<4; i++){ b[i] = (unsigned char)c[i]; } printf("b2:%d\n",*b); printf("œá¹ûΪ£º\n"); printf("%f\n", a); //printf("a:%d\n",a);}//--------------------------------------------------------------------------------------------------------------------------------------------------//
4)
#include <stdio.h>
float Hex_To_Decimal(unsigned char *Byte,int num)//Ê®ÁùœøÖƵœž¡µãÊý{ int i;char cByte[4];//·œ·šÒ» for (i=0;i<num;i++) { cByte[i] = Byte[i]; } float pfValue=*(float*)&cByte;return pfValue;return *((float*)Byte);//·œ·š¶þ}long FloatTohex(float HEX)//ž¡µãÊýµœÊ®ÁùœøÖÆת»»1{ return *( long *)&HEX;}void FloatToByte(float floatNum,unsigned char* byteArry)ž¡µãÊýµœÊ®ÁùœøÖÆת»»2{ int i;char* pchar=(char*)&floatNum;for(i=0;i<sizeof(float);i++){ *byteArry=*pchar;pchar++;byteArry++;}}void main(){ unsigned char floatToHex[4];unsigned char hexbyte[4]={0x4b,0xda,0x74,0x0c};//Ž«ÊäÊýŸÝΪ3d cc cc cdfloat 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] );//žßλÔÚÇ°}