- Bit operations in Component Pascal

From: [at]} <Wojtek>
Date: Mon, 21 Mar 2005 12:13:28 -0500 (EST)

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

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



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

e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZXJuXGZjaGFyc2V0MCBDb3VyaWVyIE5ldzt9fQ0Ke1xj
b2xvcnRibFxyZWQwXGdyZWVuMFxibHVlMDtccmVkMFxncmVlbjB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b3BlcmF0aW9ucyAiKTtccGFyDQogIFN0ZExvZy5Mbjtc
cGFyDQogIHMgOj0gXHswLDEuLjMsMTVcfTtccGFyDQogIFN0ZExvZy5TZXQgKHMpOyBTdGRMb2cu
TG47XHBhcg0KICBzIDo9IHMgKyBcezdcfTtccGFyDQogIFN0ZExvZy5TZXQgKHMpOyBTdGRMb2cu
TG47XHBhcg0KICBFWENMIChzLCAxNSk7XHBhcg0KICBTdGRMb2cuU2V0IChzKTsgU3RkTG9nLkxu
O1xwYXINCiAgcyA6PSBCSVRTICgyMik7XHBhcg0KICBpIDo9IE9SRCAocyk7XHBhcg0KICBTdGRM
b2cuSW50IChpKTsgU3RkTG9nLkxuO1xwYXINCiAgU3RkTG9nLlNldCAocyk7IFN0ZExvZy5Mbjtc
cGFyDQpccGFyDQogIEZPUiBpIDo9IDAgVE8gTUFYIChTRVQpICBET1xwYXINCiAgICAgU3RkTG9n
LkludCAoaSk7IFN0ZExvZy5TdHJpbmcgKCIgIik7XHBhcg0KICAgICBhbnMgOj0gaSBJTiBzO1xw
YXINCiAgICAgU3RkTG9nLkJvb2wgKGFucyk7XHBhcg0KICAgICBTdGRMb2cuTG47XHBhcg0KICBF
TkQ7XHBhcg0KRU5EIERvO1xwYXINClxwYXINCkVORCBUc3RTZXRFeGFtcGxlLlxwYXINClxwYXIN
CjxDVFJMLVE+IFRzdFNldEV4YW1wbGUuRG9ccGFyDQpccGFyDQotLS0gQmxhY2tCb3hccGFyDQot
LS0gc2VuZCBzdWJqZWN0IEhFTFAgb3IgVU5TVUJTQ1JJQkUgdG8gYmxhY2tib3hAb2Jlcm9uLmNo
fX0AZXMgb2YgaW5mbw==


----boundary-LibPST-iamunique-1258014823_-_---
Received on Mon Mar 21 2005 - 18:13:28 UTC

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