在单精度时:
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(非规格化)
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