我在下面找到了一个将 MBF 转换为 IEEE 的主题。
将 MBF Single 和 Double 转换为 IEEE
任何人都可以解释下面标记的代码的功能是什么?
Dim sign As Byte = mbf(6) And ToByte(&H80) 'AND (&H80) 的原因是什么?
Dim exp As Int16 = mbf(7) - 128S - 1S + 1023S '为什么是 1152 (128+1+1023)?
ieee(7) = ieee(7) 或 sign '为什么不直接将符号保存到 ieee(7)?
ieee(7) = ieee(7) 或 ToByte(exp >> 4 And &HFF) '什么是移位 4 的原因?
Public Shared Function MTID(ByVal src() As Byte, ByVal startIndex As Integer) As Double
Dim mbf(7) As Byte
Dim ieee(7) As Byte
Array.Copy(src, startIndex, mbf, 0, 8)
If mbf(7) <> 0 Then
Dim sign As Byte = mbf(6) And ToByte(&H80)
Dim exp As Int16 = mbf(7) - 128S - 1S + 1023S
ieee(7) = ieee(7) Or sign
ieee(7) = ieee(7) Or ToByte(exp >> 4 And &HFF)
ieee(6) = ieee(6) Or ToByte(exp << 4 And &HFF)
For i As Integer = 6 To 1 Step -1
mbf(i) <<= 1
mbf(i) = mbf(i) Or mbf(i - 1) >> 7
Next
mbf(0) <<= 1
For i As Integer = 6 To 1 Step -1
ieee(i) = ieee(i) Or mbf(i) >> 4
ieee(i - 1) = ieee(i - 1) Or mbf(i) << 4
Next
ieee(0) = ieee(0) Or mbf(0) >> 4
End If
Return BitConverter.ToDouble(ieee, 0)
End Function