Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with Ada.Text_IO; use Ada.Text_IO;
- with Interfaces; use Interfaces;
- procedure Main is -- The "Ada" way to do this is streams. A nice Unsigned_32'Read would do the trick and avoid the non-sense
- type Byte_Array is array (Positive range <>) of Unsigned_8;
- function To_Number (Bytes : Byte_Array) return Unsigned_32 is
- Result : Unsigned_32 := 0;
- begin
- for I in Bytes'Range loop
- Result := @ or Shift_Left (Bytes (I), (I - Bytes'First) * 8);
- end loop;
- return Result;
- end;
- Data : Byte_Array := (1 => 16#05#, 2 => 16#FF#, 3 => 16#0A#, 4 => 16#83#,
- 5 => 16#FF#, 6 => 16#00#, 7 => 16#14#, 8 => 16#D4#,
- 9 => 16#C9#, 10 => 16#DD#, 11 => 16#2C#, 12 => 16#00#,
- 13 => 16#52#, 14 => 16#7A#, 15 => 16#11#, 16 => 16#11#);
- begin
- Put_Line (To_Number (Data (1 .. 1))'Image) & " " & Unsigned_32'Image (16#0000_0005#)); -- These hardcoded results are lame
- Put_Line (To_Number (Data (1 .. 2))'Image) & " " & Unsigned_32'Image (16#0000_05FF#));
- Put_Line (To_Number (Data (1 .. 3))'Image) & " " & Unsigned_32'Image (16#0005_FF0A#));
- Put_Line (To_Number (Data (1 .. 4))'Image) & " " & Unsigned_32'Image (16#05FF_0A83#));
- Put_Line (To_Number (Data (1 .. 6))'Image) & " " & Unsigned_32'Image (16#0A83_FF00#));
- Put_Line (To_Number (Data (1 .. 8))'Image));
- Put_Line (To_Number (Data (1 .. 12))'Image));
- Put_Line (To_Number (Data (1 .. 16))'Image));
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement