Page 1 of 1

high endian code for intel

Posted: Thu Sep 25, 2003 3:45 pm
by Ozguxxx
Hi, I need some ideas about how to mutate little endian values into high endian values, god d*** jpeg files use high endian byte order and does anybody have some trick to solve this problem otherwise Ill have to call a function for every value that I read from file. I know that it is not that hard to write that function but I need a fast function, some bit shifts would do my job. Illustration:

Ozguxxx: Im in a terrible trouble and I need help!
HQ: Hold on xxx, _programming_gurus are on the way to get you out...
Ozguxxx: I hope they wont be late, I have four days to get out of this hell.
HQ: I said hold on!!!
Ozguxxx: AAAAArggghhhh!!! dzzzzzzzzzzzzzzzzzz... {noise}
HQ: All _programming_gurus contact lost to Ozguxxx, help him, NOW!

Re:high endian code for intel

Posted: Thu Sep 25, 2003 5:59 pm
by ark
I don't think there is any bit-shifting trick (at least I'm not aware of one), because you're going to be reversing the byte order:

A
B
C
D

becomes

D
C
B
A

Just like there's no memmove trick (that I'm aware of)you can use to convert the string "ABCD" into the string "DCBA".

If it's practical, it might not be a bad idea to just use an already-written function like ntohl or ntohs, which should be reasonably efficient.

Re:high endian code for intel

Posted: Fri Sep 26, 2003 1:47 am
by Perica
..

Re:high endian code for intel

Posted: Fri Sep 26, 2003 9:37 am
by Jamethiel
If you're using C/C++, look for the macros htons(), htonl(), ntohs(), and ntohl(). They are probably in <netinet/in.h> on a *nix system, and possibly in the winsock headers on a *ows system.

These macros do conversion from "network byte order" (also known as 'big endian') to "native byte order", (also known as 'the right way round') and back. They will typically be coded as inline ASM for speed.

Hope this helps.

Re:high endian code for intel

Posted: Fri Oct 03, 2003 4:44 am
by Pype.Clicker
at a lower level, doesn't the "XLATB" instruction of the CPU perform just the right transformation ?

Re:high endian code for intel

Posted: Sat Oct 04, 2003 5:24 am
by df
nah xlat is an index translation.

eg: if AL had 0x43, BX=0x100 its like doing mov al,b[bx + al] type thing...

probably why nody uses xlat, its a useless instruction :)

Re:high endian code for intel

Posted: Thu Oct 09, 2003 6:01 am
by Pype.Clicker
oops . sorry. I always mix BSWAP (which should do what requested) and XLATB :-/