TRecord =   record
  8 个 Boolean
  end;  和
  TRecord2 = record
    8 个 Byte;
  end;占用的内存一样大?我想给 8 个 Boolean 分配 一个Byte的内存 该怎么弄我目前的想法很弱智 就是 定义一个 Byte 然后  把Byte位移操作 得到 8  个Boolean 
不过这样效率不就很低了应该有好点的办法吧
不然 这个boolean 就没什么意义了

解决方案 »

  1.   

    boolean和byte占用内存是一样。Boolean-1 byte
    ByteBool-1 byte
    WordBool-2 bytes
    LongBool-4 bytes你是想用一个byte的每一位表示1个boolean,即8个boolean值?
    如果是,你的方法也是可行,效率不会低,还可以用与操作。
    boolean1: = (byteValue and 1=1)
    boolean2: = (byte and 2=2)
    boolean3: = (byteValue and 4=4)
    boolean4: = (byteValue and 8=8)
    boolean5: = (byteValue and 16=16)
    boolean6: = (byteValue and 32=32)
    boolean7: = (byteValue and 64=64)
    boolean8: = (byteValue and 128=128)
      

  2.   

    谢谢这么快就回答我了
    菜菜的再确定下boolean1: = (byteValue and 1=1)
    boolean2: = (byte and 2=2)
    boolean3: = (byteValue and 4=4)
    boolean4: = (byteValue and 8=8)
    boolean5: = (byteValue and 16=16)
    boolean6: = (byteValue and 32=32)
    boolean7: = (byteValue and 64=64)
    boolean8: = (byteValue and 128=128) 
    是单独的?
      

  3.   

    如果是要测试一个整数值Value的第Bit位是否是1的话,可以用下面的函数:function TestBit(Value: DWORD;  Bit: Byte): Boolean;
    begin
      Result := Value and (1 shl Bit) <> 0;
    end;
      

  4.   

    如果是要测试一个整数值Value的第Bit位是否是1的话,可以用下面的函数:function TestBit(Value: DWORD;  Bit: Byte): Boolean;
    begin
      Result := Value and (1 shl Bit) <> 0;
    end;
      

  5.   

    Record 类型默认是按 4 位对齐的, 在 record 前面加上 packed 才是真实大小。TRecord = packed record
      8 个 Boolean
      end;  和
      TRecord2 = packed record
        8 个 Byte;
      end;
      

  6.   


    function GetBool (SByte: Byte; Bit: Byte): Boolean;
    begin
      Result := (SByte and (1 shl Bit)) <> 0;
    end;function SetTrue (SByte: Byte; Bit: Byte): Integer;
    begin
      Result := SByte or (1 shl Bit);
    end;function SetFalse (SByte: Byte; Bit: Byte): Integer;
    begin
      Result := SByte and not (1 shl Bit);
    end;结帖