raz / conform / run / StrBytes.raz

34 lines · 826 B · raw · history · last change 7e721e08

1(* Str's byte order: le and be read, putLE and putBE write, a number
2 of up to 8 bytes, whatever the machine's own order. *)
3module StrBytes;
4import Out, Str;
5
6proc bytes(s: []U8);
7var i: INT;
8begin
9 for i := 0 to LEN(s) - 1 do
10 if i > 0 then Out.char(' '); end;
11 Out.int(I64(s[i]));
12 end;
13 Out.ln;
14end;
15
16proc main*;
17var b: [8]U8;
18begin
19 Str.putLE(b[0..8], 0102030405060708H);
20 bytes(b[0..8]);
21 Str.putBE(b[0..8], 0102030405060708H);
22 bytes(b[0..8]);
23 Out.int(I64(Str.le(b[0..8]))); Out.ln;
24 Out.int(I64(Str.be(b[0..8]))); Out.ln;
25 Str.putBE(b[0..2], 513);
26 bytes(b[0..2]);
27 Out.int(I64(Str.le(b[0..2]))); Out.ln;
28 Out.int(I64(Str.be(b[0..2]))); Out.ln;
29 Out.int(I64(Str.le(b[0..0]))); Out.ln;
30 Str.putLE(b[0..3], 0AABBCCH);
31 bytes(b[0..3]);
32end;
33
34end StrBytes.