📄 16floatpow.c
字号:
#include "stdio.h"
#include "conio.h"
#include "math.h"
htof();
ftoh();
testhex();
unsigned char AscToHex(unsigned char da);
pow_test();
void tst_pow (void);
main()
{
/* testhex();
htof();*/
ftoh();
/*pow_test();*/
}
testhex()
{
unsigned char unixtimetemp2[4];
long int unixtimetemp=0,unixtimetemp1=0;
float fvalue = 7295;
unixtimetemp2[0] = 0x11;
unixtimetemp2[1] = 0x82;
unixtimetemp2[2] = 0x7D;
unixtimetemp2[3] = 0x17;
/* unixtimetemp = (unixtimetemp2[0]*0x1000)+(unixtimetemp2[1]*0x0100)+(unixtimetemp2[2]*0x0010)+(unixtimetemp2[3]);*/
memcpy(&unixtimetemp, &fvalue, sizeof(long int));
printf("%lx",unixtimetemp);
getch();
}
htof()
{
long int dwValue = 0xCDCDCDCD ;/*42eb262c; */
float fValue=1;
memcpy(&fValue, &dwValue, sizeof(long int));
printf("%lx\n",dwValue);
printf("%f\n", fValue);
printf("%d\n",strlen(fValue));
getch();
}
ftoh()
{
long int dwValue = 0xffffffff;
float fValue=6;
memcpy(&dwValue,&fValue, sizeof(long int));
printf("%f\n", fValue);
printf("%lx",dwValue);
getch();
}
unsigned char AscToHex(unsigned char da)
{
unsigned char InstHigh = da;
if((da>='0')&&(da<='9'))
{
da = da-'0';
}
if((da>='a')&&(da<='z'))
{
da = da-'a'+10;
}
if((da>='A')&&(da<='Z'))
{
da = da-'A'+10;
InstHigh = da;
}
return da;
}
pow_test()
{ unsigned char Valtemp1[]={"122.125"};
unsigned char j;
float Valtemp2;
for(j=0;j<3;j++)
{
Valtemp2 += AscToHex(Valtemp1[j])*(pow(10,2-j));
}
for(j=0;j<4;j++)
{
Valtemp2 += AscToHex(Valtemp1[j+4])*(pow(10,-j-1));
}
printf("%f\n",Valtemp2);
getch();
}
void tst_pow (void)
{
char base;
char power;
float y;
base = 2;
power = -2;
y = pow (base, power); /* y = 256 */
printf ("%d ^ %d = %f\n", base, power, y);
getch();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -