VB6中實現浮點數各個位元組的提取
阿新 • • 發佈:2019-02-04
前面已經講過如何在vb6中實現將多個位元組還原成其實際的原始型別,那麼我們也經常需要在上位機上將浮點數等資料按照位元組進行傳輸。
廢話不多說了,直接給出系列原始碼,請參考之前的文章來看吧。
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function VarPtr Lib "MSVBVM60.DLL" (var As Any) As Long
Private Sub Command1_Click()
Dim f As Single
Dim b(4) As Byte
f = 3.14
CopyMemory ByVal VarPtr(b(0)), ByVal VarPtr(f), 1
CopyMemory ByVal VarPtr(b(1)), ByVal VarPtr(f) + 1, 1
CopyMemory ByVal VarPtr(b(2)), ByVal VarPtr(f) + 2, 1
CopyMemory ByVal VarPtr(b(3)), ByVal VarPtr(f) + 3, 1
MsgBox "0x" & Hex(b(0)) & "," & "0x" & Hex(b(1)) & "," & "0x" & Hex(b(2)) & "," & "0x" & Hex(b(3))
End Sub