如何在Julia中将字节转换为浮点/双精度



我有以下双字节:

julia> sample
8-element Array{UInt8,1}:
0xc0
0x54
0x5a
0x88
0x26
0x76
0xd3
0xd1

我知道这个替身的值是-81.41456,可以在这个网站上查看。然而,像以下这样的转换不起作用:

julia> reinterpret(Float64, sample)
1-element reinterpret(Float64, ::Array{UInt8,1}):
-1.5122920043530113e86

我可以知道将字节数组转换为浮点或双精度的正确方法吗?谢谢

问题在于Float64的构造顺序:

x=UInt8[0xd1, 0xd3, 0x76, 0x26, 0x88, 0x5a, 0x54, 0xc0];
reinterpret(Float64,x)
1-element reinterpret(Float64, ::Array{UInt8,1}):
-81.41455995182265

所以,您只需运行reinterpret(Float64,reverse(sample)),它就会工作。

最新更新