1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
with system; use System;
with text_io;
with Unchecked_Conversion;
procedure big is
le : constant integer := boolean'pos(system.default_bit_order = system.low_order_first);
be : constant integer := boolean'pos(system.default_bit_order = system.high_order_first);
type A is range 0..2**3-1;
type B is range 0..2**8-1;
type C is range 0..2**20-1;
type R is
record
d : A;
E : B;
F : C;
X : Boolean;
end record;
for R use
record
D at 0 range 0*BE+(31- 2)*LE .. 2*BE+(31- 0)*LE;
E at 0 range 3*BE+(31-10)*LE .. 10*BE+(31- 3)*LE;
F at 0 range 11*BE+(31-30)*LE .. 30*BE+(31-11)*LE;
X at 0 range 31*BE+(31-31)*LE .. 31*BE+(31-31)*LE;
end record;
type T is array(1..4) of B;
pragma Pack(T);
function Cnv is new Unchecked_Conversion(T,R);
X : constant T := (2#01100000#, 2#01000000#, 2#00000000#, 2#00000011#);
NTOH_X : constant T := (X(4), X(3), X(2), X(1)); -- fake ntohl aussi appele ntohl du pauvre.
Test : R;
begin
Test := Cnv(Ntoh_X);
Text_Io.Put_Line(A'Image(Test.d)); --> vaut 3 (2#011#)
Text_Io.Put_Line(B'Image(Test.E)); --> vaut 2 (2#00000010#)
Text_Io.Put_Line(C'Image(Test.F)); --> vaut 1 (2#00000000000000000001#)
Text_Io.Put_Line(Boolean'Image(Test.X)); vaut TRUE.
end big; |
Partager