February 17th, 2000, 11:53 AM
I am reading in a file which is in binary form, and has been ouputted from a machine which uses big endian format. I need to get the information into little endian format.
I am reading in a long, and know how to get it either as a big endian long, or as a set of 4 bytes, but dont know how to go from this point, to forming the little endian long.
Please help me!
Ravi Kiran
February 17th, 2000, 10:54 PM
Take a look at this: If you understand what is happening, you would be able to apply for your case:
A small little hack using copying memory blocks.
option Explicit
private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest as Any, pSource as Any, byval dwLength as Long)
private Sub Form_Load()
Dim i as Integer
Dim long1 as Long, long2 as Long
Dim cbuf1(3) as Byte, cbuf2(3) as Byte
Dim plong1 as Long, plong2 as Long
long1 = &HBBBBFFFF
plong1 = VarPtr(long1)
plong2 = VarPtr(long2)
CopyMemory byval plong2, byval (plong1 + 2), 2
CopyMemory byval (plong2 + 2), byval plong1, 2
Debug.print Hex$(long1) ' "BBBBFFFF"
Debug.print Hex$(long2) ' "FFFFBBBB"
' USING Byte arrays: as read from a file, say:
cbuf1(0) = &HAA
cbuf1(1) = &HAA
cbuf1(2) = &HFF
cbuf1(3) = &HFF
for i = 0 to 3
Debug.print Hex$(cbuf1(i)); '-> "AAAAFFFF"
next i
Debug.print
CopyMemory cbuf2(0), cbuf1(2), 2
CopyMemory cbuf2(2), cbuf1(0), 2
for i = 0 to 3
Debug.print Hex$(cbuf2(i)); '-> "FFFFAAAA"
next i
End Sub
ps: If you are using these for reading big files, check which is the best method from perf. point of view.
RK
February 18th, 2000, 07:30 AM
Thank you, this was very helpful!