使用 Base 16(十六进制)打印整数
设置变量 Default_Base
在 Ada.Text_IO.Integer_IO
的实例上设置; 另外,Default_Width
设置为输出不能有前导空格。
with Ada.Text_IO; use Ada.Text_IO;
procedure Print_Hex is
subtype Count is Integer range -1_000_000 .. 1_000_000;
package Count_IO is new Integer_IO (Count);
X : Count;
begin
Count_IO.Default_Width := 1;
Count_IO.Default_Base := 16;
X := Count'First;
while X < Count'Last loop
Count_IO.Put (X);
New_Line;
X := X + 500_000;
end loop;
end Print_Hex;
结果
-16#F4240#
-16#7A120#
16#0#
16#7A120#