1,在开发过程中,我们经常要用到浮点型数据,但是计算机中保存的数据是二进制数据,所有我们需要掌握二进制数据(16进制)转换位浮点型数据,我现在来举例说明:
#include<stdio.h>
int main()
{
long int y = 0xfffffffffffffff7;
int z = 0xffffffff;
double * x = (double*)&y;
printf("*x=%lf\n",*x);
float *absent_value = (float*)&z;
printf("absent = %f\n",*absent_value);
}
2,float数据到int(char a[4])的转化
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
float temp = 100.0;
//浮点数转为二进制数
char *int_temp = (char*)&temp;
printf("int_temp[0] = %d\n",int_temp[0]);
printf("int_temp[1] = %d\n",int_temp[1]);
printf("int_temp[2] = %d\n",int_temp[2]);
printf("int_temp[3] = %d\n",int_temp[3]);
char char_temp[4];
char_temp[0] = 0;
char_temp[1] = 0;
char_temp[2] = -56;
char_temp[3]