如何把 Byte 数据转换为二进制数据,并保存于数组中?然后,我读取数组中的0/1数据来进行具体的处理。有能力者请给出示例代码!!!

解决方案 »

  1.   

    function ByteToBin(Value: Byte): string;
      const
      V: Byte = 1;
      var
        i: Integer;
      begin
        for i:= 7 downto 0 do
          if (V shl i) and Value <> 0 then
            Result := Result + '1'
          else
            Result := Result + '0';
      end;
      

  2.   

    var
      b: Byte;
      s: string;
      IntI: Integer;
      function ByteToBin(Value: Byte): string;
      const
      V: Byte = 1;
      var
        i: Integer;
      begin
        for i:= 7 downto 0 do
          if (V shl i) and Value <> 0 then
            Result := Result + '1'
          else
            Result := Result + '0';
      end;
    begin
      b:= $c;
      s:= ByteToBin( b );
      for IntI:= 1 to Length( s ) do
      begin
        self.ListBox1.Items.Add( s[ IntI ] );
      end;
    end;