source: buchla-68k/lib700/bitrev.c@ 8aad29e

Last change on this file since 8aad29e was d18a473, checked in by Thomas Lopatic <thomas@…>, 7 years ago

No more warnings in lib700.

  • Property mode set to 100644
File size: 924 bytes
Line 
1/*
2 =============================================================================
3 bitrev.c -- bit reverse function
4 Version 1 -- 1987-03-24 -- D.N. Lynx Crowe
5 =============================================================================
6*/
7
8#include "ram.h"
9
10static uint16_t bitmask[] = {
11
12 0x0001, 0x0002, 0x0004, 0x0008,
13 0x0010, 0x0020, 0x0040, 0x0080,
14 0x0100, 0x0200, 0x0400, 0x0800,
15 0x1000, 0x2000, 0x4000, 0x8000
16};
17
18/*
19 =============================================================================
20 bitrev(bitsin, nbits) -- reverses the rightmost nbits of bitsin.
21
22 Any bits to the left of the reversed bits in the result will be zeros.
23 =============================================================================
24*/
25
26uint16_t bitrev(uint16_t bitsin, int16_t nbits)
27{
28 uint16_t n;
29 int16_t m;
30
31 n = 0;
32
33 for (m = 0; m < nbits; m++)
34 if (bitsin & bitmask[m])
35 n |= bitmask[nbits-1-m];
36
37 return(n);
38}
39
Note: See TracBrowser for help on using the repository browser.