Solved

Converting Little Endian Byte Array To Long

Posted on 2003-11-22
2
685 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

687 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