×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

# Contact US

Log In

#### Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
To Your Posts
• Keyword Search
• One-Click Access To Your
Favorite Forums
• Automated Signatures
On Your Posts
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

# How can I convert Big-endian to Little-endian efficiently?2

 Forum Search FAQs Links MVPs

## How can I convert Big-endian to Little-endian efficiently?

(OP)
I have a several Long numbers that are stored in Big-endian and I want to convert then Little-endian. How can I do this efficiently?

### RE: How can I convert Big-endian to Little-endian efficiently?

Hi JLMartin!

Hmmm. Two methods come to mind:

1) Call the Winsock function htonl() or ntohl() depending on the direction you want to go

2) Do something ugly (but removes dependency on Winsock) like:

Dim s1, s2, s3, s4 as byte
s1 = (Num And &HFF000000) / &H01000000
s2 = (Num And &H00FF0000) / &H00010000
s3 = (Num And &H0000FF00) / &H00000100
s4 = Num And &H000000FF
Num = (s4 * &H00100000) + (s3 * &H00010000) + (s2 * &H00000100) + s1

NOTE: I haven't tested this code - you might need to play around with the AND statements, but it looks good.

Chip H.

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

### Reply To This Thread

#### Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!

Already a member? Close this window and log in.