-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathutil_bits.h
56 lines (51 loc) · 1.45 KB
/
util_bits.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const uint8_t aReverseNibble[ 16 ] =
{
0x0 // 0 0000 -> 0000
,0x8 // 1 0001 -> 1000
,0x4 // 2 0010 -> 0100
,0xC // 3 0011 -> 1100
,0x2 // 4 0100 -> 0010
,0XA // 5 0101 -> 1010
,0x6 // 6 0110 -> 0110
,0xE // 7 0111 -> 1110
,0x1 // 8 1000 -> 0001
,0x9 // 9 1001 -> 1001
,0x5 // A 1010 -> 0101
,0xD // B 1011 -> 1101
,0x3 // C 1100 -> 0011
,0xB // D 1101 -> 1011
,0x7 // E 1110 -> 0111
,0xF // F 1111 -> 1111
};
// ========================================================================
inline
uint8_t ReverseBits4( uint8_t n )
{
return aReverseNibble[ n & 0xF ];
}
// Example:
// 1 2 -> 4 8
// 0001_0010 -> 0100_1000
// ========================================================================
inline
uint8_t ReverseBits8( uint8_t n )
{
return (aReverseNibble[ (n >> 0) & 0xF ] << 4)
| (aReverseNibble[ (n >> 4) & 0xF ] << 0);
}
// ========================================================================
inline
uint16_t ReverseBits16( uint16_t n )
{
return (ReverseBits8( n >> 0 ) << 8)
| (ReverseBits8( n >> 8 ) << 0);
}
inline
uint16_t ReverseNibbles( uint16_t n )
{
return 0
| (aReverseNibble[(glyph >> 12) & 0xF] << 0)
| (aReverseNibble[(glyph >> 8) & 0xF] << 4)
| (aReverseNibble[(glyph >> 4) & 0xF] << 8)
| (aReverseNibble[(glyph >> 0) & 0xF] << 12);
}