造价通

反馈
取消

热门搜词

造价通

取消 发送 反馈意见

IEEE754标准演变

2018/06/19162 作者:佚名
导读: 从二进制到浮点数 在单精度时:M=1.f(二进制)(规格化exp≠0&≠255)M=0.f(非规格化exp=0)Bias=127V=(-1)^s*2^(E-Bias)*M(规格化)V=(-1)^s*2^(1-Bias)*M(非规格化)在双精度时:Bias=1023M=1.f(二进制)(规格化exp≠0&≠2047)M=0.f(非规格化exp=0)V=(-1)^s*2

从二进制到浮点数

在单精度时:

M=1.f(二进制)(规格化exp≠0&≠255)M=0.f(非规格化exp=0)

Bias=127

V=(-1)^s*2^(E-Bias)*M(规格化)

V=(-1)^s*2^(1-Bias)*M(非规格化)

在双精度时:

Bias=1023

M=1.f(二进制)(规格化exp≠0&≠2047)M=0.f(非规格化exp=0)

V=(-1)^s*2^(E-Bias)*M(规格化)

V=(-1)^s*2^(1-Bias)*M(非规格化)

VB中的函数

API:Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)

函数:

Public Function GetDoubleBinary(dd As Double) As String

Dim b(0 To 7) As Byte

Dim s As String

CopyMemory b(0), dd, 8

For j = 7 To 0 Step -1

For i = 7 To 0 Step -1

s = s & IIf((b(j) And (2 ^ i)) > 0, "1", "0")

'以下添加分割符

Select Case j * 8 + i

Case 63

s = s & "|"

Case 52

s = s & "|"

End Select

Next

Next

GetDoubleBinary = s

End Function

Public Function GetSingleBinary(ss As Single) As String

Dim b(0 To 3) As Byte

Dim s As String

CopyMemory b(0), ss, 4

For j = 3 To 0 Step -1

For i = 7 To 0 Step -1

s = s & IIf((b(j) And (2 ^ i)) > 0, "1", "0")

'以下添加分割符

Select Case j * 8 + i

Case 31

s = s & "|"

Case 23

s = s & "|"

End Select

Next

Next

GetSingleBinary = s

End Function

*文章为作者独立观点,不代表造价通立场,除来源是“造价通”外。
关注微信公众号造价通(zjtcn_Largedata),获取建设行业第一手资讯

热门推荐

相关阅读