使用 Base 16(十六進位制)列印整數

設定變數 Default_BaseAda.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#