Converting decimal/integer to binary - how and why it works the way it does?

后端 未结 6 1409
無奈伤痛
無奈伤痛 2020-12-11 10:15

As already asked David in a comment of an answer here, I\'m really interested on how this function works, since I can\'t seem to get the same (correct) values if changing re

6条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-11 10:25

    function TForm1.Dec2Bin(iDec: Integer): string;
    begin
      Result:='';
    while iDec>0 do
      begin
        Result:=IntToStr(iDec and 1)+Result;
        iDec:=iDec shr 1;
      end;
    end;
    

提交回复
热议问题