#include "endian.h"
#include "types.h"

void swap_endian16( void* data, int len )
{
    word16 tmp16;
    byte* tmp16_as_bytes = (byte*) &tmp16;
    word16* data_as_word16s = (word16*) data;
    byte* data_as_bytes;
    int i;
    
    for ( i = 0; i < len; i++ )
    {
	tmp16 = data_as_word16s[ i ];
	data_as_bytes = (byte*) &( data_as_word16s[ i ] );
	
	data_as_bytes[ 0 ] = tmp16_as_bytes[ 1 ];
	data_as_bytes[ 1 ] = tmp16_as_bytes[ 0 ];
    }
}

void swap_endian32( void* data, int len )
{
    word32 tmp32;
    byte* tmp32_as_bytes = (byte*) &tmp32;
    word32* data_as_word32s = (word32*) data;
    byte* data_as_bytes;
    int i;
    
    for ( i = 0; i < len; i++ )
    {
	tmp32 = data_as_word32s[ i ];
	data_as_bytes = (byte*) &( data_as_word32s[ i ] );
	
	data_as_bytes[ 0 ] = tmp32_as_bytes[ 3 ];
	data_as_bytes[ 1 ] = tmp32_as_bytes[ 2 ];
	data_as_bytes[ 2 ] = tmp32_as_bytes[ 1 ];
	data_as_bytes[ 3 ] = tmp32_as_bytes[ 0 ];
    }
}
