home *** CD-ROM | disk | FTP | other *** search
- -- Chapter 30 - Programming exercise 1
- with Text_IO, Unchecked_Conversion;
- use Text_IO;
-
- procedure CH30_1 is
-
- package Int_IO is new Text_IO.Integer_IO(INTEGER);
- use Int_IO;
-
- NUMBER_OF_BYTES : constant := 2;
-
- 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 CH30_1;
-
-
-
-
- -- Result of Execution
-
- -- Int_Data = 253 Split_Array = 253 0
- -- Int_Data = 254 Split_Array = 254 0
- -- Int_Data = 255 Split_Array = 255 0
- -- Int_Data = 256 Split_Array = 0 1
- -- Int_Data = 257 Split_Array = 1 1
- -- Int_Data = 258 Split_Array = 2 1
- -- Int_Data = 259 Split_Array = 3 1
- -- Int_Data = 260 Split_Array = 4 1
-
- -- Note that the fields are apparently reversed because of the
- -- way the bytes are stored in the microprocessor used for this
- -- example program.
-
-