home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
cpm
/
turbopas
/
tp
/
utl2
/
utl2.lbr
/
BITMAP2.PZS
/
BITMAP2.PAS
Wrap
Pascal/Delphi Source File
|
1987-04-26
|
2KB
|
76 lines
PROGRAM bit_map2;
(*
Original work by Steve Fox
Bit_Map2 modifications by W. Mabee, CRNA and H. Kaemerrer.
Demonstrates compression of 8 boolean variables into a single
byte. Anyone know if you can accomplish the same thing with
shl or shr.
*)
CONST
header = 'Test < Bit Mapping Routine >';
VAR
more,response : CHAR;
ans : ARRAY[1..8] OF BOOLEAN;
hold : BYTE;
i : INTEGER;
PROCEDURE set_bits(VAR flag : BYTE; a,b,c,d,e,f,g,h : BOOLEAN);
BEGIN
flag := 0;
IF a THEN flag := flag OR $80;
IF b THEN flag := flag OR $40;
IF c THEN flag := flag OR $20;
IF d THEN flag := flag OR $10;
IF e THEN flag := flag OR $08;
IF f THEN flag := flag OR $04;
IF g THEN flag := flag OR $02;
IF h THEN flag := flag OR $01
END;
PROCEDURE get_bits(flag : BYTE; VAR a,b,c,d,e,f,g,h : BOOLEAN);
BEGIN
a := (flag AND $80 <> 0);
b := (flag AND $40 <> 0);
c := (flag AND $20 <> 0);
d := (flag AND $10 <> 0);
e := (flag AND $08 <> 0);
f := (flag AND $04 <> 0);
g := (flag AND $02 <> 0);
h := (flag AND $01 <> 0)
END;
PROCEDURE set_up_screen;
BEGIN
CLRSCR; WRITELN; WRITELN(header); WRITELN;
END;
BEGIN
REPEAT
set_up_screen;
FOR i := 1 TO 8 DO
BEGIN
WRITE('Question # ',i,' Answer Y/N : ');
READ(KBD,response); WRITELN(UPCASE(response));
ans[i] := (response IN ['Y','y'])
END;
set_bits(hold,ans[1],ans[2],ans[3],ans[4],ans[5],ans[6],ans[7],ans[8]);
get_bits(hold,ans[1],ans[2],ans[3],ans[4],ans[5],ans[6],ans[7],ans[8]);
WRITELN;
FOR i := 1 TO 8 DO
BEGIN
WRITE('Bit # ',i);
IF ans[i] = TRUE THEN WRITELN(' is true.') ELSE WRITELN(' is false.');
END;
WRITELN;
WRITE('The byte has a value of ',hold,'. Want to run it again ? ');
READ(KBD,more); more := UPCASE(more);
UNTIL more <> 'Y';
END.