Solved

Converting Little Endian Byte Array To Long

Posted on 2003-11-22
2
665 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now