tparray16.pp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. { from gpc tests, original name pack4.pas }
  2. {$ifdef fpc}
  3. {$bitpacking on}
  4. {$endif fpc}
  5. Program PackUnpack;
  6. Var
  7. foo: array [ 1..7 ] of Boolean;
  8. bar: packed array [ 1..3 ] of Boolean;
  9. i: Integer;
  10. temp: Boolean;
  11. begin
  12. for i:= 1 to 3 do
  13. bar [ i ]:= true;
  14. for i:= 1 to 7 do
  15. foo [ i ]:= false;
  16. foo [ 4 ]:= true;
  17. foo [ 5 ]:= true;
  18. pack ( foo, 3, bar );
  19. if bar [ 3 ] and bar [ 2 ] and not bar [ 1 ] then
  20. begin
  21. for i:= 1 to 3 do
  22. begin
  23. temp:= not bar [ i ];
  24. bar [ i ]:= temp;
  25. end { for };
  26. unpack ( bar, foo, 5 );
  27. if not foo [ 1 ] and not foo [ 2 ] and not foo [ 3 ] and foo [ 4 ]
  28. and foo [ 5 ] and not foo [ 6 ] and not foo [ 7 ] then
  29. writeln ( 'OK' )
  30. else
  31. begin
  32. write ( 'failed: foo =' );
  33. for i:= 1 to 7 do
  34. write ( ' ', foo [ i ] );
  35. writeln;
  36. halt(1);
  37. end { else };
  38. end { if }
  39. else
  40. begin
  41. write ( 'failed: bar =' );
  42. for i:= 1 to 3 do
  43. write ( ' ', bar [ i ] );
  44. writeln;
  45. halt(1);
  46. end { else };
  47. end.