- Bit operations in Component Pascal

From: Hof, Philipp <"Hof,>
Date: Wed, 30 Mar 2005 08:25:41 +1200

----boundary-LibPST-iamunique-905277879_-_-
Content-type: text/plain

Some more bit operations:
http://www.elec.canterbury.ac.nz/publicarea/staff/hof/p50-win/p020-set.html



-----Original Message-----
From: Wojtek Skulski [mailto:skulski{([at]})nowhere.xy
Sent: Tuesday, 22 March 2005 5:13 a.m.
To: blackbox{([at]})nowhere.xy
Subject: [BlackBox] - Bit operations in Component Pascal

Hi:

  one of the most useful features of Component Pascal,
and perhaps least appreciated, are the bit manipulation
intrinsics of the CP language. Today I showed the following
program to one of my collegaues who was wondering how to
manipulate bits. I am posting this program as a possible
addition to the CP documentation being discussed on this list.

It is wonderful to go back and forth between bitsets and integers
and be able to manipulate bits directly without any obscurations.

MODULE TstSetExample;
IMPORT StdLog;

PROCEDURE Do *;
  VAR s : SET;
      i : INTEGER;
      ans : BOOLEAN;
BEGIN
  StdLog.String (" Example set operations ");
  StdLog.Ln;
  s := {0,1..3,15};
  StdLog.Set (s); StdLog.Ln;
  s := s + {7};
  StdLog.Set (s); StdLog.Ln;
  EXCL (s, 15);
  StdLog.Set (s); StdLog.Ln;
  s := BITS (22);
  i := ORD (s);
  StdLog.Int (i); StdLog.Ln;
  StdLog.Set (s); StdLog.Ln;

  FOR i := 0 TO MAX (SET) DO
     StdLog.Int (i); StdLog.String (" ");
     ans := i IN s;
     StdLog.Bool (ans);
     StdLog.Ln;
  END;
END Do;

END TstSetExample.

<CTRL-Q> TstSetExample.Do

--- BlackBox
--- send subject HELP or UNSUBSCRIBE to blackbox{([at]})nowhere.xy

--- BlackBox
--- send subject HELP or UNSUBSCRIBE to blackbox{([at]})nowhere.xy



----boundary-LibPST-iamunique-905277879_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"

e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz

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GFyDQogIFN0ZExv
Zy5TZXQgKHMpOyBTdGRMb2cuTG47XHBhcg0KXHBhcg0KICBGT1IgaSA6PSAwIFRPIE1BWCAoU0VU
KSAgRE9ccGFyDQogICAgIFN0ZExvZy5JbnQgKGkpOyBTdGRMb2cuU3RyaW5nICgiICIpO1xwYXIN
CiAgICAgYW5zIDo9IGkgSU4gcztccGFyDQogICAgIFN0ZExvZy5Cb29sIChhbnMpO1xwYXINCiAg
ICAgU3RkTG9nLkxuO1xwYXINCiAgRU5EO1xwYXINCkVORCBEbztccGFyDQpccGFyDQpFTkQgVHN0
U2V0RXhhbXBsZS5ccGFyDQpccGFyDQo8Q1RSTC1RPiBUc3RTZXRFeGFtcGxlLkRvXHBhcg0KXHBh
cg0KLS0tIEJsYWNrQm94XHBhcg0KLS0tIHNlbmQgc3ViamVjdCBIRUxQIG9yIFVOU1VCU0NSSUJF
IHRvIGJsYWNrYm94QG9iZXJvbi5jaFxwYXINClxwYXINCi0tLSBCbGFja0JveFxwYXINCi0tLSBz
ZW5kIHN1YmplY3QgSEVMUCBvciBVTlNVQlNDUklCRSB0byBibGFja2JveEBvYmVyb24uY2hccGF9
fQBsYW1wLnZl


----boundary-LibPST-iamunique-905277879_-_---
Received on Tue Mar 29 2005 - 21:25:41 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:28:20 UTC