fork download
  1. with Ada.Text_IO; use Ada.Text_IO;
  2. with Ada.Unchecked_Conversion;
  3. with Interfaces; use Interfaces;
  4.  
  5. procedure Main is
  6. package Unsigned_32_IO is new Ada.Text_IO.Modular_IO (Unsigned_32);
  7.  
  8. type Bit_Array_32_Index is range 0 .. 31;
  9. type Bit_Array_17_Index is range 0 .. 16;
  10. type Bit_Array_32 is array (Bit_Array_32_Index) of Boolean with Component_Size => 1, Size => 32;
  11. type Bit_Array_17 is array (Bit_Array_17_Index) of Boolean with Component_Size => 1, Size => 32;
  12.  
  13. generic
  14. type I is (<>);
  15. type T is array (I) of Boolean;
  16. procedure Generic_Put (Item : T; Width : Field; Base : Number_Base);
  17. procedure Generic_Put (Item : T; Width : Field; Base : Number_Base) is
  18. function Convert_To_Unsigned_32 is new Ada.Unchecked_Conversion (T, Unsigned_32);
  19. begin
  20. Unsigned_32_IO.Put (Convert_To_Unsigned_32 (Item), Width, Base);
  21. end;
  22.  
  23. generic
  24. type I is (<>);
  25. type T is array (I) of Boolean;
  26. function Generic_Shift_Left (Value : Unsigned_32; Amount : Natural) return T;
  27. function Generic_Shift_Left (Value : Unsigned_32; Amount : Natural) return T is
  28. function Convert_To_Bit_Array_32 is new Ada.Unchecked_Conversion (Unsigned_32, T);
  29. begin
  30. return Convert_To_Bit_Array_32 (Interfaces.Shift_Left (Value, Amount));
  31. end;
  32.  
  33. function Shift_Left is new Generic_Shift_Left (Bit_Array_32_Index, Bit_Array_32);
  34. function Shift_Left is new Generic_Shift_Left (Bit_Array_17_Index, Bit_Array_17);
  35. procedure Put is new Generic_Put (Bit_Array_32_Index, Bit_Array_32);
  36. procedure Put is new Generic_Put (Bit_Array_17_Index, Bit_Array_17);
  37.  
  38. B32 : Bit_Array_32 with Volatile;
  39. B17 : Bit_Array_17 with Volatile;
  40. begin
  41. B32 := Shift_Left (1, 2) or Shift_Left (1, 5);
  42. B17 := Shift_Left (1, 2) or Shift_Left (1, 5);
  43. Put (B17, 0, 2);
  44. New_Line;
  45. Put (B32, 0, 2);
  46. end;
Success #stdin #stdout 0s 5816KB
stdin
Standard input is empty
stdout
2#100100#
2#100100#