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!
high endian code for intel
Re:high endian code for intel
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.
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
..
Last edited by Perica on Sun Dec 03, 2006 9:17 pm, edited 1 time in total.
Re:high endian code for intel
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.
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.
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:high endian code for intel
at a lower level, doesn't the "XLATB" instruction of the CPU perform just the right transformation ?
Re:high endian code for intel
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
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
-- Stu --
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:high endian code for intel
oops . sorry. I always mix BSWAP (which should do what requested) and XLATB :-/