RosettaCodeData/Task/Binary-digits/Free-Pascal/binary-digits.free

24 lines
643 B
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

program binaryDigits(input, output, stdErr);
{$mode ISO}
function binaryNumber(const value: nativeUInt): shortString;
const
one = '1';
var
representation: shortString;
begin
representation := binStr(value, bitSizeOf(value));
// strip leading zeroes, if any; NB: mod has to be ISO compliant
delete(representation, 1, (pos(one, representation)-1) mod bitSizeOf(value));
// traditional Pascal fashion:
// assign result to the (implicitely existent) variable
// that is named like the functions name
binaryNumber := representation;
end;
begin
writeLn(binaryNumber(5));
writeLn(binaryNumber(50));
writeLn(binaryNumber(9000));
end.