convert from BIG-ENDIAN to LITTLE-ENDIAN

Discussion in 'C++' started by hicham, Jun 30, 2003.

  1. hicham

    hicham Guest

    Hi,

    I am looking for help, i would like to know how can i use the endian.h and
    config.h to convert compiled files under solaris from BIG-ENDIAN to compiled
    files LITTLE-ENDIAN.

    I am working under linux debian 3.0 woody

    Thank you for your help.
     
    hicham, Jun 30, 2003
    #1
    1. Advertising

  2. hicham wrote:
    > Hi,
    >
    > I am looking for help, i would like to know how can i use the endian.h and
    > config.h to convert compiled files under solaris from BIG-ENDIAN to compiled
    > files LITTLE-ENDIAN.
    >
    > I am working under linux debian 3.0 woody
    >
    > Thank you for your help.
    >
    >


    Standard C++ has no header files named config.h and endian.h. So we
    can't help with issues relating to those header files. Try a Solaris
    newsgroup.

    Converting from Big Endian to Little Endian involve swapping bytes.
    You can either write your own or search the STL. There seems to
    be very little code differences between writing your own function
    and a library version; since swapping is that big of a function.

    --
    Thomas Matthews

    C++ newsgroup welcome message:
    http://www.slack.net/~shiva/welcome.txt
    C++ Faq: http://www.parashift.com/c -faq-lite
    C Faq: http://www.eskimo.com/~scs/c-faq/top.html
    alt.comp.lang.learn.c-c++ faq:
    http://www.raos.demon.uk/acllc-c /faq.html
    Other sites:
    http://www.josuttis.com -- C++ STL Library book
     
    Thomas Matthews, Jun 30, 2003
    #2
    1. Advertising

  3. hicham

    dxcoder Guest

    > > I am looking for help, i would like to know how can i use the endian.h
    and
    > > config.h to convert compiled files under solaris from BIG-ENDIAN to

    compiled
    > > files LITTLE-ENDIAN.


    uint8_t* input = ...;
    uint32_t v = input[0] | (input[1] << 8) | (input[2] << 16) | (input[3] <<
    24);

    This sort of arrangement generally gets the job done, no matter what which
    of those endianess architechture you're on. It's more complicated issue if
    you want to please this NG regulars, since:

    - C++ doesn't guarantee that datatypes have precisely 8, 16 or 32 bits on
    them. On those machines you have to do this at bit-level, most modern
    architechtures support 8-bit chars and generally char,short,int,long, etc.
    are multiplies of 8 bits.

    Hmmm, so you just need to get typedefs right for uint8_t and uint32_t, and
    rest should work out okay. Even if this NG regulars find this statement
    fundamentally flawed, this (shifting to build up larger word) is what you
    will find on most real-world UN*X sources for handling endianess.

    The key is that you will have to know what endianess the stream/file is, so
    that you can do the shifting of "input" in correct order. Some binary files
    store values in big-endian (.lwo for example) and some in little-endian
    (.3ds, for example). There is also BCP (?) endianess, which is rarely seen
    in real-world since the platforms are novadays obsolete, so it's safe to
    ignore those (again, stating this with NG regular disclaimer).


    --
    -xXx-
     
    dxcoder, Jul 2, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ernst Murnleitner

    float: IEEE, big endian, little endian

    Ernst Murnleitner, Jan 13, 2004, in forum: C++
    Replies:
    0
    Views:
    881
    Ernst Murnleitner
    Jan 13, 2004
  2. invincible

    Little Endian to Big Endian

    invincible, Jun 14, 2005, in forum: C++
    Replies:
    9
    Views:
    14,383
    Old Wolf
    Jun 14, 2005
  3. invincible
    Replies:
    1
    Views:
    552
    red floyd
    Jun 14, 2005
  4. hicham

    convert from big-endian to little-endian

    hicham, Jun 30, 2003, in forum: C Programming
    Replies:
    0
    Views:
    1,533
    hicham
    Jun 30, 2003
  5. Replies:
    5
    Views:
    375
    Stephen Sprunk
    Aug 31, 2006
Loading...

Share This Page