-- Chapter 32 - Programming exercise 2 with Ada.Text_IO, Unchecked_Conversion; use Ada.Text_IO; procedure CH32_2 is package Int_IO is new Ada.Text_IO.Integer_IO(INTEGER); use Int_IO; package Flt_IO is new Ada.Text_IO.Float_IO(FLOAT); use Flt_IO; NUMBER_OF_BYTES : constant := 4; type CHAR_ARRAY is array(1..NUMBER_OF_BYTES) of CHARACTER; Split_Array : CHAR_ARRAY; Float_Data : FLOAT := 1.0; function Switch_To_Bits is new Unchecked_Conversion( Source => FLOAT, Target => CHAR_ARRAY); begin for Index in 1..8 loop Split_Array := Switch_To_Bits(Float_Data); Put("Float_Data ="); Put(Float_Data, 6, 2, 0); Put(" Split_Array ="); for Count in 1..NUMBER_OF_BYTES loop Put(CHARACTER'POS(Split_Array(Count)), 4); end loop; New_Line; Float_Data := Float_Data * 2.0; end loop; end CH32_2; -- Result of Execution -- Float_Data = 1.00 Split_Array = 0 0 128 63 -- Float_Data = 2.00 Split_Array = 0 0 0 64 -- Float_Data = 4.00 Split_Array = 0 0 128 64 -- Float_Data = 8.00 Split_Array = 0 0 0 65 -- Float_Data = 16.00 Split_Array = 0 0 128 65 -- Float_Data = 32.00 Split_Array = 0 0 0 66 -- Float_Data = 64.00 Split_Array = 0 0 128 66 -- Float_Data = 128.00 Split_Array = 0 0 0 67 -- Note that the fields are apparently reversed because of the -- way the bytes are stored in the microprocessor used for this -- example program.