Last change
on this file since e225e77 was 7258c6a, checked in by Thomas Lopatic <thomas@…>, 8 years ago |
Use standard integer types.
|
-
Property mode
set to
100644
|
File size:
893 bytes
|
Rev | Line | |
---|
[f40a309] | 1 | /*
|
---|
| 2 | =============================================================================
|
---|
| 3 | bitrev.c -- bit reverse function
|
---|
| 4 | Version 1 -- 1987-03-24 -- D.N. Lynx Crowe
|
---|
| 5 | =============================================================================
|
---|
| 6 | */
|
---|
| 7 |
|
---|
[7258c6a] | 8 | static int16_t bitmask[] = {
|
---|
[f40a309] | 9 |
|
---|
| 10 | 0x0001, 0x0002, 0x0004, 0x0008,
|
---|
| 11 | 0x0010, 0x0020, 0x0040, 0x0080,
|
---|
| 12 | 0x0100, 0x0200, 0x0400, 0x0800,
|
---|
| 13 | 0x1000, 0x2000, 0x4000, 0x8000
|
---|
| 14 | };
|
---|
| 15 |
|
---|
| 16 | /*
|
---|
| 17 | =============================================================================
|
---|
| 18 | bitrev(bitsin, nbits) -- reverses the rightmost nbits of bitsin.
|
---|
| 19 |
|
---|
| 20 | Any bits to the left of the reversed bits in the result will be zeros.
|
---|
| 21 | =============================================================================
|
---|
| 22 | */
|
---|
| 23 |
|
---|
[7258c6a] | 24 | int16_t bitrev(int16_t bitsin, int16_t nbits)
|
---|
[f40a309] | 25 | {
|
---|
[7258c6a] | 26 | int16_t m, n;
|
---|
[f40a309] | 27 |
|
---|
| 28 | n = 0;
|
---|
| 29 |
|
---|
| 30 | for (m = 0; m < nbits; m++)
|
---|
| 31 | if (bitsin & bitmask[m])
|
---|
| 32 | n |= bitmask[nbits-1-m];
|
---|
| 33 |
|
---|
| 34 | return(n);
|
---|
| 35 | }
|
---|
| 36 |
|
---|
Note:
See
TracBrowser
for help on using the repository browser.