Solved

Converting Little Endian Byte Array To Long

Posted on 2003-11-22
2
674 Views
Last Modified: 2007-12-19
Greetings!

I would like to know how to convert a Little Endian byte array to a long value. I already have a code for Big Endian to Long:

For i = LBound(ByteArray) To UBound(ByteArray)
        Return = ShiftLeft(Return, 8) + ByteArray(i)
Next i

ShiftLeft is a function which shifts a value n bits to the left (SHL ; <<).

For Little Endian to Long, I am currently using a loop, which will "mirror" an array and then pass it to the Big Endian to Long function, but that is slow - especially when there are lots of items.
I thought there might be some built in functions or APIs which could accelerate the whole process.

Sebastian Mares
0
Comment
Question by:Sebastian_Mares
2 Comments
 
LVL 7

Accepted Solution

by:
Z_Beeblebrox earned 30 total points
ID: 9810605
Hi,

Since little endian is the format used by Intel (x86) you can use the CopyMemory API to do the conversion directly.

Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)

CopyMemory Return, ByteArray(0), 4

Zaphod.
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question