Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ada 1.48 KB | None | 0 0
  1.  
  2. with Ada.Text_IO; use Ada.Text_IO;
  3. with Interfaces;  use Interfaces;
  4.  
  5. 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
  6.  
  7.   type Byte_Array is array (Positive range <>) of Unsigned_8;
  8.  
  9.   function To_Number (Bytes : Byte_Array) return Unsigned_32 is
  10.     Result : Unsigned_32 := 0;
  11.     begin
  12.       for I in Bytes'Range loop
  13.         Result := @ or Shift_Left (Bytes (I), (I - Bytes'First) * 8);
  14.       end loop;    
  15.       return Result;
  16.     end;
  17.  
  18.   Data : Byte_Array := (1 => 16#05#,  2 => 16#FF#,  3 => 16#0A#,  4 => 16#83#,
  19.                         5 => 16#FF#,  6 => 16#00#,  7 => 16#14#,  8 => 16#D4#,
  20.                         9 => 16#C9#, 10 => 16#DD#, 11 => 16#2C#, 12 => 16#00#,
  21.                        13 => 16#52#, 14 => 16#7A#, 15 => 16#11#, 16 => 16#11#);
  22.  
  23. begin
  24.   Put_Line (To_Number (Data (1 ..  1))'Image) & " " & Unsigned_32'Image (16#0000_0005#)); -- These hardcoded results are lame
  25.   Put_Line (To_Number (Data (1 ..  2))'Image) & " " & Unsigned_32'Image (16#0000_05FF#));
  26.   Put_Line (To_Number (Data (1 ..  3))'Image) & " " & Unsigned_32'Image (16#0005_FF0A#));
  27.   Put_Line (To_Number (Data (1 ..  4))'Image) & " " & Unsigned_32'Image (16#05FF_0A83#));
  28.   Put_Line (To_Number (Data (1 ..  6))'Image) & " " & Unsigned_32'Image (16#0A83_FF00#));
  29.   Put_Line (To_Number (Data (1 ..  8))'Image));
  30.   Put_Line (To_Number (Data (1 .. 12))'Image));
  31.   Put_Line (To_Number (Data (1 .. 16))'Image));
  32. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement