這是我如何從一種格式轉換arbitary數據到另一個。
Private Type LongByte
H1 As Byte
H2 As Byte
L1 As Byte
L2 As Byte
End Type
Private Type LongType
L As Long
End Type
Function SwapEndian(ByVal LongData as Long) as Long
Dim TempL As LongType
Dim TempLB As LongByte
Dim TempVar As Long
TempL.L = LongData
LSet TempLB = TempL
'Swap is a subroutine I wrote to swap two variables
Swap TempLB.H1, TempLB.L2
Swap TempLB.H2, TempLB.L1
LSet TempL = TempLB
TempVar = TempL.L
SwapEndian = TempVar
End Function
如果您正在使用FileIO專注打交道,那麼你可以使用TempLB
的字節字段
訣竅是使用LSET VB6
如果您使用的是.NET的一個不起眼的命令,然後做的過程要容易得多。這裏的技巧是使用MemoryStream來檢索和設置單個字節。現在你可以爲int16/int32/int64做數學運算。但是如果你正在處理浮點數據,那麼使用LSET或者MemoryStream就會更加清晰和容易調試。
如果您使用的是Framework 1.1或更高版本,那麼您有使用字節數組的BitConvertor類。
Private Structure Int32Byte
Public H1 As Byte
Public H2 As Byte
Public L1 As Byte
Public L2 As Byte
Public Function Convert() As Integer
Dim M As New MemoryStream()
Dim bR As IO.BinaryReader
Dim bW As New IO.BinaryWriter(M)
Swap(H1, L2)
Swap(H2, L1)
bW.Write(H1)
bW.Write(H2)
bW.Write(L1)
bW.Write(L2)
M.Seek(0, SeekOrigin.Begin)
bR = New IO.BinaryReader(M)
Convert = bR.ReadInt32()
End Function
End Structure
qCompress/qUncompress只是周圍的zlib的包裝。 – 2008-10-07 12:48:47