source: buchla-68k/lib700/mangle.c@ 0580615

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

Point of no return.

  • Property mode set to 100644
File size: 1.5 KB
Line 
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 mangle(long *bitmap, short nb, long ib)
23{
24 register long bm; /* scan mask */
25 register long rv; /* result value */
26 register short bn; /* bit number (bitmap index) */
27
28 bm = 0x00000001L; /* setup scan mask */
29 rv = 0x00000000L; /* clear the output word */
30
31 for (bn = 0; bn < nb; bn++) { /* scan across nb bits */
32
33 if (ib & bm) /* if the input bit is 1 */
34 rv |= bitmap[bn]; /* 'OR' the bitmap into rv */
35
36 bm <<= 1; /* shift the scan mask left */
37 }
38
39 return(rv); /* return rv as the result */
40}
Note: See TracBrowser for help on using the repository browser.