Files
mercury/tests/hard_coded/uint32_from_bytes.m
Julien Fischer 95ce71d683 Add conversion functions from bytes (uint8s) to 32-bit integers.
library/int32.m:
library/uint32.m:
     As above.

tests/hard_coded/Mmakefile:
tests/hard_coded/int32_from_bytes.{m,exp}:
tests/hard_coded/uint32_from_bytes.{m,exp}:
     Test the new functions.
2017-11-01 00:52:16 -04:00

30 lines
956 B
Mathematica

:- module uint32_from_bytes.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module uint32.
main(!IO) :-
Test1 = uint32.from_bytes_le(0x00u8, 0x00u8, 0x00u8, 0xffu8),
io.write_line(Test1, !IO),
Test2 = uint32.from_bytes_le(0x00u8, 0x00u8, 0xffu8, 0x00u8),
io.write_line(Test2, !IO),
Test3 = uint32.from_bytes_le(0x00u8, 0xffu8, 0x00u8, 0x00u8),
io.write_line(Test3, !IO),
Test4 = uint32.from_bytes_le(0xffu8, 0x00u8, 0x00u8, 0x00u8),
io.write_line(Test4, !IO),
Test5 = uint32.from_bytes_be(0x00u8, 0x00u8, 0x00u8, 0xffu8),
io.write_line(Test5, !IO),
Test6 = uint32.from_bytes_be(0x00u8, 0x00u8, 0xffu8, 0x00u8),
io.write_line(Test6, !IO),
Test7 = uint32.from_bytes_be(0x00u8, 0xffu8, 0x00u8, 0x00u8),
io.write_line(Test7, !IO),
Test8 = uint32.from_bytes_be(0xffu8, 0x00u8, 0x00u8, 0x00u8),
io.write_line(Test8, !IO).