Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7864349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:45:38+00:00 2026-06-02T23:45:38+00:00

I am writing an ELF analyzer, but I’m having some trouble converting endianness properly.

  • 0

I am writing an ELF analyzer, but I’m having some trouble converting endianness properly. I have functions to determine the endianness of the analyzer and the endiannness of the object file.

Basically, there are four possible scenarios:

  1. A big endian compiled analyzer run on a big endian object file
    • nothing needs converted
  2. A big endian compiled analyzer run on a little endian object file
    • the byte order needs swapped, but ntohs/l() and htons/l() are both null macros on a big endian machine, so they won’t swap the byte order. This is the problem
  3. A little endian compiled analyzer run on a big endian object file
    • the byte order needs swapped, so use htons() to swap the byte order
  4. A little endian compiled analyzer run on a little endian object file.
    • nothing needs converted

Is there a function I can use to explicitly swap byte order/change endianness, since ntohs/l() and htons/l() take the host’s endianness into account and sometimes don’t convert? Or do I need to find/write my own swap byte order function?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T23:45:39+00:00Added an answer on June 2, 2026 at 11:45 pm

    Do I need to find/write my own swap byte order function?

    Yes you do. But, to make it easy, I refer you to this question: How do I convert between big-endian and little-endian values in C++? which gives a list of compiler specific byte order swap functions, as well as some implementations of byte order swap functions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Writing some classes for a Framework extension, and I have the following code: public
Writing some XML documentation for a predicate helper class. But I can't figure out
currently I'm writing little program that reads elf file header and prints some information
Writing a test app to emulate PIO lines, I have a very simple Python/Tk
Writing documentation in html requires some code examples. What to do with characters that
While writing some C code, I decided to compile it to assembly and read
Writing a lexer of .java source files in Java. I have a stream of
Writing some drag&drop code, I'd like to cancel the click events in my mouseup
I am writing a simple user-space ELF loader under Linux (why? for 'fun'). My
I'm in the process of writing a compiler that will be generating ELF executable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.