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
Solved

Converting Little Endian Byte Array To Long

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying 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

Suggested Solutions

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.
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…
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…

790 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