2016 Update
This commit is contained in:
parent
948b86eafa
commit
dcf5d15da3
7965 changed files with 139854 additions and 31002 deletions
29
Task/Binary-digits/Pascal/binary-digits-1.pascal
Normal file
29
Task/Binary-digits/Pascal/binary-digits-1.pascal
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
program IntToBinTest;
|
||||
{$MODE objFPC}
|
||||
uses
|
||||
strutils;//IntToBin
|
||||
function WholeIntToBin(n: NativeUInt):string;
|
||||
var
|
||||
digits: NativeInt;
|
||||
begin
|
||||
// BSR?Word -> index of highest set bit but 0 -> 255 ==-1 )
|
||||
IF n <> 0 then
|
||||
Begin
|
||||
{$ifdef CPU64}
|
||||
digits:= BSRQWord(NativeInt(n))+1;
|
||||
{$ELSE}
|
||||
digits:= BSRDWord(NativeInt(n))+1;
|
||||
{$ENDIF}
|
||||
WholeIntToBin := IntToBin(NativeInt(n),digits);
|
||||
end
|
||||
else
|
||||
WholeIntToBin:='0';
|
||||
end;
|
||||
procedure IntBinTest(n: NativeUint);
|
||||
Begin
|
||||
writeln(n:12,' ',WholeIntToBin(n));
|
||||
end;
|
||||
BEGIN
|
||||
IntBinTest(5);IntBinTest(50);IntBinTest(5000);
|
||||
IntBinTest(0);IntBinTest(NativeUint(-1));
|
||||
end.
|
||||
Loading…
Add table
Add a link
Reference in a new issue