cpbits.pas

来自「生物信息学中的遗传数据分析的delphi源码。」· PAS 代码 · 共 51 行

PAS
51
字号
{$I CPDIR.INC}


unit cpbits;

{*

  Byte-size bitmasks

  2/8/91

*}

interface

type
   BITLIST = array[0..7] of byte;

const
   BITS = 8;
   BITMASK:BITLIST = ($0001,$0002,$0004,$0008,
   		      $0010,$0020,$0040,$0080);
   NULL_MASK = $0000;
   FULL_MASK = $00FF;

   function BitIsOn (ithBit, flag:byte):Boolean;
   procedure BitOn  (ithBit:byte; var flag:byte);
   procedure BitOff (ithBit:byte; var flag:byte);

implementation

   function BitIsOn (ithBit, flag:byte):Boolean;
   { True if ith bit in flag is on }
   begin
      BitIsOn := (flag AND BITMASK[ithBit] = BITMASK[ithBit]);
   end;

   procedure BitOn (ithBit:byte; var flag:byte);
   { Switch on the ith bit in flag }
   begin
      flag := flag OR BITMASK[ithBit];
   end;

   procedure BitOff (ithBit:byte; var flag:byte);
   { Switch off the ith bit in flag }
   begin
      flag := flag AND NOT BITMASK[ithBit];
   end;

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?