-- Chapter 32 - Programming exercise 1 with Ada.Text_IO, Unchecked_Conversion; use Ada.Text_IO; procedure CH32_1 is package Int_IO is new Ada.Text_IO.Integer_IO(INTEGER); use Int_IO; NUMBER_OF_BYTES : constant := 4; type CHAR_ARRAY is array(1..NUMBER_OF_BYTES) of CHARACTER; Split_Array : CHAR_ARRAY; Int_Data : INTEGER; function Switch_To_Bits is new Unchecked_Conversion( Source => INTEGER, Target => CHAR_ARRAY); begin for Index in 253..260 loop Int_Data := Index; Split_Array := Switch_To_Bits(Int_Data); Put("Int_Data ="); Put(Int_Data, 6); Put(" Split_Array ="); for Count in 1..NUMBER_OF_BYTES loop Put(CHARACTER'POS(Split_Array(Count)), 4); end loop; New_Line; end loop; end CH32_1; -- Result of Execution -- Int_Data = 253 Split_Array = 253 0 0 0 -- Int_Data = 254 Split_Array = 254 0 0 0 -- Int_Data = 255 Split_Array = 255 0 0 0 -- Int_Data = 256 Split_Array = 0 1 0 0 -- Int_Data = 257 Split_Array = 1 1 0 0 -- Int_Data = 258 Split_Array = 2 1 0 0 -- Int_Data = 259 Split_Array = 3 1 0 0 -- Int_Data = 260 Split_Array = 4 1 0 0 -- Note that the fields are apparently reversed because of the -- way the bytes are stored in the microprocessor used for this -- example program.