'What is the scientific calculation method of 0xf.ap+11 hexadecimal to decimal?
Your similar hex ox2ab, aef97, etc, I understand its scientific notation, but 0xf.ap+11 makes me wonder.Can anyone help me, thanks!
Solution 1:[1]
It is the hexadecimal floating-point representation available with C99.
The significant portion 0xf.a is expressed in the way each digit has
the power of 16 according to the position:
0xf.a = 0xf (= 15 * 16^0) + 0x.a (= 10 * 16^-1)
= 15 + 10 / 15
while the exponent portion indicates the power of two:
p+11 = 2^11
then
0xf.ap+11 = (15 + 10 / 16) * 2048
= 30720 + 1280
= 32000
In actual C code you can say something like:
int main()
{
double x = 0xf.ap+11;
printf("%f\n", x); // it will print 32000.000000
double y = 32000.0;
printf("%a\n", y); // it will print 0x1.f4p+14
return 0;
}
You'll find the both 0xf.ap+11 and 0x1.f4p+14 are equal to 32000.0. It looks surprising two different expression have the identical numbers.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | tshiono |
