Next: BitPackClass
Up: simlib
Previous: linkage
BitFiddleClass
NAME
bitfiddleclass - Routines to do bit manipulation on 32-bit
integers.
DESCRIPTION
The routines in this class do bit-mainpulation on 32-bit
integers. They are implemented in assembler for speed. They
might be useful to do low level interfacing and as a compact
way to store Booleans.
EXAMPLE
external class bitfiddleClass;
ref(bitfiddleclass) Fiddler;
integer i, mask=16RFF000000;
Fiddler:-new bitfiddleclass;
Fiddler.bit0high; !-- set bit mapping to left->right --;
i:=Fiddler.BitSet(i,31); !- set the least sign. bit of
i;
i:=Fiddler.BitAnd(i,mask); !- mask out most sign. byte of
i;
1:=Fiddler.BitShift(i,-2); !- divide by 4 (and zero-fill
signbit)
AUTHOR
Boris Magnusson, Lund University.
DETAILED INTERFACE
class BitFiddleClass;
Operations for logical bitwise manipulations on 32-bit
integers.
This class only specifies operations and have no state
varaiables. All data to the operations are given as
paramaters.
The class might serve useful to use this class as a super
class for more specialized abstractions, such as
BitSetClass.
Supers: -
Kind: Instantiable
Init: none (Defualt Bit0Low)
Sequencing: (Bit0Low / Bit0High / BitClear / BitSet / BitGet
/ BitNot / BitAnd BitIor / BitXor / BitFirst / BitShift)*
OPERATIONS
Bit0Low
procedure Bit0Low;
Set bitordering so bit number 0 is the least significant
bit.
bitnumbering: 31,30,29,...,0 (bit 0 lowest significans, bit
31 is sign).
This is default.
Bit0High
procedure Bit0High;
Set bitordering so bit number 0 is the most significant bit.
bitnumbering: 0,1,2,..,31 (bit 0 is signbit, bit 31 is least
significant.)
BitClear
integer procedure BitClear(i,bno);
integer i; ! Input bitpattern;
integer bno; ! Affected bit number;
Return the value of i with bit numbered bno cleared (=0).
BitSet
integer procedure BitSet(i,bno);
integer i; ! Input bitpattern;
integer bno; ! Affected bit number;
Return the value of i with bit numbered bno set (=1).
BitGet
Boolean procedure BitGet(i,bno);
integer i; ! Input bitpattern;
integer bno; ! Affected bit number;
Return Value of bit bno of i.
BitNot
integer procedure BitNot (i);
integer i; ! Input bitpattern;
Return the bitwise inverted value of i.
BitAnd
integer procedure BitAnd(i,j);
integer i,j; ! Input bitpatterns;
Return the result of i AND j calculated bitwise.
BitIor
integer procedure BitIor(i,j);
integer i,j; ! Input bitpatterns;
Return the result of i IOR j calculated bitwise.
BitXor
integer procedure BitXor(i,j);
integer i,j; ! Input bitpatterns;
Return the bit-number of the first set bit in i. If there
is no set bit, the result is -1.
BitFirst
integer procedure BitFirst(i);
integer i; ! Input bitpattern;
Return the bit-number of the first set bit in i. If there
is no set bit, the result is -1.
BitShift
integer procedure BitShift(i,s);
integer i; ! Input bitpattern;
integer s; ! multiplication with 2**s;
Return the integer result of shifting i s steps. If Bit0low
this means shifting left (s>0) or right (s<0). If Bit0High
the shift direction is reversed so shift left corresponds to
multiplication and right to division in both cases. This is
a logical shift, so all bits shifted in are zeroes.