用十六进制表示浮点数

huangapple go评论78阅读模式
英文:

Representing a float as a hexadecimal

问题

我正在学习浮点数类型,例子是一个用十六进制表示的浮点数变量声明:

float f_in_hex = 0x1.59a8f6p8f

这是计算浮点数值的过程:

(1 * 16^0 + 5 * 16^-1 + 9 * 16^-2 + 10 * 16^-3 + 8 * 16^-4 + 15 * 16^-5 + 6 * 16^-6) * 2^8

所以,我知道前缀 0x 表示 基数为16,但我仍然不理解指数部分为什么从0开始,并且带有负值。

英文:

I'm studying the float-point type and the examples is a declaration of a variable float expressed as an hexadecimal

float f_in_hex = Ox1.59a8f6p8f

This is the computation to find the float value:

(1 * 16^0 + 5 * 16^-1 + 9 * 16^-2 + 10 * 16^-3 + 8 * 16^-4 + 15 * 16^-5 + 6 * 16^-6) * 2^8

So, I know what is the prefix Ox, that base is 16 but I still don't understand why the exponential part start from 0 and goes with negative values

答案1

得分: 1

它是负值,因为它在小数点后面。

16^(-1) 相当于 1/16 = 0.0625。

如果是正指数,它将变成一个很大的数。

希望你明白我的意思。

英文:

it's negative value because it's after the decimal point

16^(-1) is the same as 1/16 = .0625

if it was positive exponent it would be a big number.

hope you understand what i mean

答案2

得分: -1

这不是一个十六进制数字,首先 "Ox" 是字母 "O",不是零。然后,在所谓的十六进制数字中,有一个字母 "p",而十六进制数字只包括从 "a" 到 "f"。

英文:

that is not a hexadecimal number, firstly Ox is the letter O and it is not a zero, then within the supposed hexadecimal numbers there is a letter p, the hexadecimal numbers only cover from a-f

huangapple
  • 本文由 发表于 2020年9月23日 23:29:15
  • 转载请务必保留本文链接:https://go.coder-hub.com/64031342.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定