convert from BIG-ENDIAN to LITTLE-ENDIAN

H

hicham

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

Thomas Matthews

hicham said:
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
 
D

dxcoder

I am looking for help, i would like to know how can i use the endian.h
and
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).
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top