Solved

# endian conversion using algorithms and template

Posted on 2005-03-04

In order to convert a value from big endian to little endian, I could convert value to a native value, assemble the number, using the

proper multipliers. So now - doing this from memory I could do:

unsigned char big[4]; // single value in big-endian order

unsigned long x;

x = ((big[0] * 0x100UL + big[1]) * 0x100 + big[2]) * 0x100 + big[3];

I'm sure there's a combination of algorithms and templates that could achieve this but that's where I'm lacking / hence asking for help converting from big to little and vice versa. Something akin to:

template<typename T>

T swap_endian( T begin, T end )

{

// some algorithm .. maybe

}

int main()

{

}