My machine is little-endian (Intel byte order). I need to read a binary file containing 16-bit signed integer data in Motorola/IEEE byte order (\"big-endian\"), then do some
Here is a simple ASCII conversion:
Public Function SwapLong(Data As Long) As Long
Const Sz As Integer = 3
Dim Bytes(Sz) As Byte
Dim n As Integer
Dim HexStr As String
Dim SwpStr As String
HexStr = Right("00000000" + Hex(Data), 2 * (Sz + 1))
SwpStr = vbNullString
For n = 0 To Sz
SwpStr = SwpStr + Mid(HexStr, (Sz - n) * 2 + 1, 2)
Next n
SwapLong = CLng("&h" + SwpStr)
End Function
Public Function SwapInt(Data As Integer) As Integer
Const Sz As Integer = 1
Dim Bytes(Sz) As Byte
Dim n As Integer
Dim HexStr As String
Dim SwpStr As String
HexStr = Right("0000" + Hex(Data), 2 * (Sz + 1))
SwpStr = vbNullString
For n = 0 To Sz
SwpStr = SwpStr + Mid(HexStr, (Sz - n) * 2 + 1, 2)
Next n
SwapInt = CInt("&h" + SwpStr)
End Function