source: buchla-68k/orig/CLIBRARY/MANGLE.C@ 6d3de83

Last change on this file since 6d3de83 was 3ae31e9, checked in by Thomas Lopatic <thomas@…>, 8 years ago

Imported original source code.

  • Property mode set to 100755
File size: 1.7 KB
RevLine 
[3ae31e9]1/*
2 =============================================================================
3 mangle.c -- mangle a bit stream
4 Version 2 -- 1987-08-28 -- D.N. Lynx Crowe
5 (c) Copyright 1987 - D.N. Lynx Crowe
6 =============================================================================
7*/
8
9/*
10 =============================================================================
11 mangle(bitmap, nb, ib) -- reorder the 'nb' least significant bits
12 in 'ib' according to 'bitmap'. Assumes that 'bitmap' is at least 'nb'
13 words long, and that nb <= 32. The 'bitmap' translation table contains
14 an output word for each bit in the input word, with each 'bitmap' entry
15 corresponding to the bit number matching its index. For example,
16 'bitmap[0]' contains the word which will be 'OR'ed into the output if
17 the least significant bit of the input word is set, while 'bitmap[31]'
18 corresponds to the most significant bit of the input word.
19 =============================================================================
20*/
21
22long
23mangle(bitmap, nb, ib)
24register long *bitmap; /* bit map table pointer */
25register short nb; /* number of least significant input bits */
26register long ib; /* input data (in nb least significant bits) */
27{
28 register long bm; /* scan mask */
29 register long rv; /* result value */
30 register short bn; /* bit number (bitmap index) */
31
32 bm = 0x00000001L; /* setup scan mask */
33 rv = 0x00000000L; /* clear the output word */
34
35 for (bn = 0; bn < nb; bn++) { /* scan across nb bits */
36
37 if (ib & bm) /* if the input bit is 1 */
38 rv |= bitmap[bn]; /* 'OR' the bitmap into rv */
39
40 bm <<= 1; /* shift the scan mask left */
41 }
42
43 return(rv); /* return rv as the result */
44}
Note: See TracBrowser for help on using the repository browser.