home *** CD-ROM | disk | FTP | other *** search
- unit bits;
-
- { Written by William C. Thompson }
-
- { This unit is intended to be used in programs which do a lot
- of bit manipulation. }
-
- interface
-
- const two:array[0..15] of word=(1,2,4,8,16,32,64,128,256,512,
- 1024,2048,4096,8192,16384,32768);
-
- function bset(n:word; p:byte):word;
- function bclr(n:word; p:byte):word;
- function btst(n:word; p:byte):boolean;
- function asl(n:word; i:byte):word;
- function asr(n:word; i:byte):word;
- function lsl(n:word; i:byte):word;
- function lsr(n:word; i:byte):word;
-
- implementation
-
- function bset(n:word; p:byte):word;
- { sets the pth bit of n }
- begin
- bset:=n or two[p]
- end;
-
- function bclr(n:word; p:byte):word;
- { clears the pth bit of n }
- begin
- bclr:=n and (65535-two[p])
- end;
-
- function btst(n:word; p:byte):boolean;
- { returns if pth bit is 1 }
- begin
- btst:=n and two[p]>0
- end;
-
- function asl(n:word; i:byte):word;
- { performs i arithmetic left-shifts on n }
- begin
- asl:=n*two[i]
- end;
-
- function asr(n:word; i:byte):word;
- { performs i arithmetic right-shifts on n }
- begin
- asr:=n div two[i]
- end;
-
- function lsl(n:word; i:byte):word;
- { performs i logical left-shifts on n }
- begin
- { As yet unfinished }
- end;
-
- function lsr(n:word; i:byte):word;
- { performs i logical right-shifts on n }
- begin
- { As yet unfinished }
- end;
-
- end.
-