ARM7 REV RBIT REV16

 1 // Reverse the bit order in a 32-bit word.
 2 unsigned int rbit(
 3   unsigned int i )
 4 {
 5   i = ( ( i & 0x55555555 ) << 1 ) | ( ( i >> 1 ) & 0x55555555 );
 6   i = ( ( i & 0x33333333 ) << 2 ) | ( ( i >> 2 ) & 0x33333333 );
 7   i = ( ( i & 0x0f0f0f0f ) << 4 ) | ( ( i >> 4 ) & 0x0f0f0f0f );
 8   i = ( i << 24 ) | ( ( i & 0xff00 ) << 8 ) //
 9     | ( ( i >> 8 ) & 0xff00 ) | ( i >> 24 );
10   return i;
11 }
12 
13 // Reverse byte order in each halfword independently
14 // converts 16-bit big-endian data into little-endian data
15 // or 16-bit little-endian data into big-endian data
16 short rev16(
17   short s )
18 {
19   return ( s << 8 ) | ( s >> 8 );
20 }
21 
22 // Reverse byte order in a word
23 // converts 32-bit big-endian data into little-endian data
24 // or 32-bit little-endian data into big-endian data.
25 unsigned int rev(
26   unsigned int i )
27 {
28   return ( i & 0x000000FFU ) << 24 | ( i & 0x0000FF00U ) << 8
29     | ( i & 0x00FF0000U ) >> 8 | ( i & 0xFF000000U ) >> 24;
30 }

 

posted @ 2013-01-05 20:06  IAmAProgrammer  阅读(856)  评论(0编辑  收藏  举报