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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
\defmodule {bitset}
This module defines sets of bits and useful operations for such sets.
Some of these operations are implemented as macros.
\code\hide
/* bitset.h for ANSI C */
#ifndef BITSET_H
#define BITSET_H
#include <testu01/gdef.h>
\endhide\endcode
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\guisec{Constants}
\code
extern unsigned long bitset_maskUL[];
\endcode
\tab {\tt bitset\_maskUL[j]} has bit $j$ set to 1 and all other bits set to
0. Bit 0 is the least significant bit.
\endtab
\code
extern unsigned long bitset_MASK[];
\endcode
\tab {\tt bitset\_MASK[j]} has all the first $j$ bits set to 1 and all other
bits set to 0. Bit 0 is the least significant bit.
\endtab
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\guisec{Types}
\code
typedef unsigned long bitset_BitSet;
\endcode
\tab Set of bits. Bits are numbered starting from 0 for the least
significant bit. If bit $s$ is 1, then element $s$ is a member of
the set, otherwise not.
\endtab
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\guisec{Macros}
\noindent
{\tt bitset\_SetBit (S, b)};
\tab Sets bit {\tt b} in set {\tt S} to 1.
\endtab
\code
\hide
#define bitset_SetBit(S, b) ((S) |= (bitset_maskUL[b]))
\endhide
\endcode
\noindent
{\tt bitset\_ClearBit (S, b)};
\tab Sets bit {\tt b} in set {\tt S} to 0.
\endtab
\code
\hide
#define bitset_ClearBit(S, b) ((S) &= ~(bitset_maskUL[b]))
\endhide
\endcode
\noindent
{\tt bitset\_FlipBit (S, b)};
\tab Flips bit {\tt b} in set {\tt S}; thus,
$0 \rightarrow 1$ and $1 \rightarrow 0$.
\endtab
\code
\hide
#define bitset_FlipBit(S, b) ((S) ^= (bitset_maskUL[b]))
\endhide
\endcode
\noindent
{\tt bitset\_TestBit (S, b)};
\tab Returns the value of bit {\tt b} in set {\tt S}.
\endtab
\code
\hide
#define bitset_TestBit(S, b) ((S) & (bitset_maskUL[b]) ? 1 : 0)
\endhide
\endcode
\noindent
{\tt bitset\_RotateLeft (S, t, r)};
\tab Rotates the {\tt t} bits of set {\tt S} by {\tt r} bits to the left.
{\tt S} is considered as a {\tt t}-bit number kept
in the least significant bits of the equivalent number {\tt S}.
\endtab
\code
\hide
#define bitset_RotateLeft(S, t, r) do { \
unsigned long v853 = (S) >> ((t) - (r)); \
(S) <<= (r); (S) |= v853; (S) &= bitset_MASK[t]; \
} while (0)
\endhide
\endcode
\noindent
{\tt bitset\_RotateRight (S, t, r)};
\tab Rotates the {\tt t} bits of set {\tt S} by {\tt r} bits to the right.
{\tt S} is considered as a {\tt t}-bit number kept
in the least significant bits of the equivalent number {\tt S}.
\endtab
\code
\hide
#define bitset_RotateRight(S, t, r) do { \
unsigned long v972 = (S) >> (r); \
(S) <<= ((t) - (r)); (S) |= v972; (S) &= bitset_MASK[t]; \
} while (0)
\endhide
\endcode
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\guisec{Prototypes}
\code
bitset_BitSet bitset_Reverse (bitset_BitSet Z, int s);
\endcode
\tab Reverses the {\tt s} least significant bits of {\tt Z} considered as a
number. Thus, if {\tt s}${}=4$ and {\tt Z}${}=0011$, the returned value is $1100$.
\endtab
\code
void bitset_WriteSet (char *desc, bitset_BitSet Z, int s);
\endcode
\tab
Prints the string {\tt desc} (which may be empty), then writes the {\tt
s} least significant bits of {\tt Z} considered as an unsigned binary number.
This corresponds to the {\tt s} first elements of {\tt Z}.
\endtab
\code
\hide
#endif
\endhide
\endcode
|