How does 0x12.2P2
equal 72.5?
I know that the value following the P, called the binary exponent, indicates the power-of-two by which the number is multiplied?
Floating-point literals are numbers that have a decimal point or an exponential part. They can be represented as: Real literals. Binary floating-point literals.
2. Which of the following is a valid floating-point literal? Explanation: To make a floating point literal, we should attach a suffix of 'f' or 'F' and there should not be any blank space. 3.
Integer literals represent fixed integer values like 900, 12, 400, -222 etc. (with in the integer range). Whereas, floating point literals represents fractional values i.e. numbers with decimal values like 25.53, 45.66, 58.66 etc. while writing these literals we should use the notation f or F as 25.53.
Floating-point decimal values generally do not have an exact binary representation. This is a side effect of how the CPU represents floating point data. For this reason, you may experience some loss of precision, and some floating-point operations may produce unexpected results.
0x12.2P2
is 0x122 / 1610 * 22
More formally (?), for the part before the P
, you can use this very classic conversion table:
decimal point here ▼
+-----+-----+-----+-----+-+-----+-----+-----+
| 16³ | 16² | 16¹ | 16⁰ | | 16⁻¹| 16⁻²| 16⁻³|
+-----------------------------------------+
| | | 1 | 2 |.| 2 | | |
+-----+-----+-----+-----+-+-----+-----+-----+
So 0x12.2 is 1⨯16¹+2x16⁰+2⨯16⁻¹ = 18.125
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With