如果有个10进制数X,如何转到2进制并呈现在Edit上?谢谢

解决方案 »

  1.   


    function Dec2Bin(value : Integer; MinBit : Integer) : string;begin  result := '';  while (value > 0) do  begin    if (Trunc(value / 2) * 2 = value) then      result := '0' + result    else Result := '1' + Result;    value := Trunc(value / 2);  end;  //填满MaxBit位  while (Length(Result) < MinBit) Do Result := '0' + Result;end;
      

  2.   

    数字都是二进制的,想用二进制显示可以使用IntToBin 
      

  3.   


    function IntToBin(AValue: LongInt; ASize: Integer): String;
    var
      I: Integer;
    begin
        Result:= EmptyStr;
        for I:= ASize - 1 downto 0 do
        begin
           if AValue and (1 shl I) = 0 then
                Result:= Result + '0'
            else
                Result:= Result + '1';
        end;
    end;
    procedure TForm1.Button1Click(Sender: TObject);
    begin
        Edit1.Text:= IntToBin(3,8)
    end;