C語言實現32位反轉如下:
void Rev32InByte( void *val )
{
unsigned int v = *((unsigned int *)val) ;
v = ((v & 0x000000FF) << 24) | ((v & 0x0000FF00) << 8) |
((v & 0x00FF0000) >> 8) | ((v & 0xFF000000) >> 24) ;
*((unsigned int *)val) = v ;
};
C語言實現16位反轉如下:
void Rev16InByte( void *val )
{
unsigned short v = *((unsigned short *)val) ;
v = ((v & 0x00FF) << 8) | ((v & 0xFF00) >> 8) ;
*((unsigned short *)val) = v ;
};