Unit Bits; {***************************************************************************} {* Bit 0 is the LSB, Bit 7 is the MSB {***************************************************************************} interface {***************************************************************************} {***************************************************************************} Function DeciVal(BitNum: byte): byte; Function Flip(InByte: byte; BitNum: byte): byte; Function IsHigh(InByte: byte; BitNum: byte): boolean; Function SetLow(InByte: byte; BitNum: byte): byte; Function SetHigh(InByte: byte; BitNum: byte): byte; implementation {***************************************************************************} {***************************************************************************} Function DeciVal(BitNum: byte): byte; {***************************************************************************} begin case BitNum of 0: DeciVal := 1; 1: DeciVal := 2; 2: DeciVal := 4; 3: DeciVal := 8; 4: DeciVal := 16; 5: DeciVal := 32; 6: DeciVal := 64; 7: DeciVal := 128; else write(#7); end; end; Function Flip(InByte: byte; BitNum: byte): byte; {***************************************************************************} var BitVal: byte; Temp: byte; begin BitVal := DeciVal(BitNum); if BitVal and InByte = BitVal then Temp := SetLow(InByte, BitNum) else Temp := SetHigh(InByte, BitNum); Flip := Temp; end; Function IsHigh(InByte: byte; BitNum: byte): boolean; {***************************************************************************} var Temp: boolean; begin Temp := InByte and DeciVal(BitNum) = DeciVal(BitNum); IsHigh := Temp; end; Function SetLow(InByte: byte; BitNum: byte): byte; {***************************************************************************} var BitVal: integer; begin BitVal := DeciVal(BitNum); SetLow := InByte and (255 - BitVal); end; Function SetHigh(InByte: byte; BitNum: byte): byte; {***************************************************************************} var BitVal: integer; begin BitVal := DeciVal(BitNum); SetHigh := InByte or BitVal; end; {***************************************************************************} {***************************************************************************} {***************************************************************************} begin end.