Page 1 of 1

littel to big endian question...

Posted: Sat Mar 20, 2010 9:37 pm
by Tuxedo
HI ALL!
I'm working on a routine to convert littel to big endian longwords and get some problem...
maybe I'm only a newbe guy...
To convert shorts was all really simple! I use a ror(or rol) and all works great :)
The poblem was when I try to convert longs...probably I miss some function but I cant reach to swap the position for bytes to convert from little to big...
Any idea here?
I know that i have to swap the bytes of a long(for ex: 1,2,3,4 to 4,3,2,1) but I cant found any function in hollywood to do that...

Thanks a LOT!!!!!!

Re: littel to big endian question...

Posted: Sun Mar 21, 2010 6:13 pm
by Tuxedo
Solved :)
Simply copied a C method since the bitwise opertors was the same in Hollywood too :)
ANd I've miss the bitwise operators of Hollywood since today... :P

So topic closed :P

Re: littel to big endian question...

Posted: Wed Mar 24, 2010 3:45 pm
by Clyde
Would be cool if you would share the solution you found in case someone else also gets in trouble on this topic. :-)

Thanks!

Re: littel to big endian question...

Posted: Wed Mar 24, 2010 8:53 pm
by Tuxedo
Well...
I find rather easly the code:

inline void endian_swap(unsigned short& x)
{
x = (x>>8) |
(x<<8);
}

inline void endian_swap(unsigned int& x)
{
x = (x>>24) |
((x<<8) & 0x00FF0000) |
((x>>8) & 0x0000FF00) |
(x<<24);
}

On the net...
Than sonce the logical commands was exactly the same in Hollywood too I simply adapted that to my code :)
Easy :)

The full link was here:

http://www.codeguru.com/forum/showthread.php?t=292902

Hope that was usefull to someone :)