ETH官方钱包

前往
大廳
主題

ieee754 浮點數轉unsigned 32位元 再變16進位 2020/6/8

艾倫D索妮雅 | 2021-06-10 20:05:25 | 巴幣 0 | 人氣 500

ex.
int main()
{
float A = 100;
float B = -125.53125;
printf("%X\n",(unsigned int ) A);
printf("%08X\n",*(unsigned int *) &B);
return 0;
}
A:
100=>1100100.000000.....(先轉2進制)
=1.100100000000x2^6(浮點數格式)
exp:127+6=133 =>10000101(2進制)
S(符號1bit)=0
exp(8bit)=10000101
fraction(小數23bit)=10010000000000000000000
變成unsigned(32bit)就是
01000010110010000000000000000000
16進位(每4bit一組)
0100 ===>4
0010 ===>2
1100 ===>C
1000 ===>8
0000 ===>0
0000 ===>0
0000 ===>0
0000 ===>0
答: 42C80000
---------------------------------------------------
B:
-125.53125=>1111101.10001(二進制)
=1.11110110001x2^6
exp:127+6=133=>10000101
S(符號1bit)=1
exp(8bit)=10000101
fraction(小數23bit)=11110110001000000000000
變成unsigned(32bit)就是
11000010111110110001000000000000
16進位(每4bit一組)
1100 ===>C
0010 ===>2
1111 ===>F
1011 ===>B
0001 ===>1
0000 ===>0
0000 ===>0
0000 ===>0
答:C2FB1000

創作回應

更多創作