Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Bit manipulation in ISO Modula-2

97 views
Skip to first unread message

Robert

unread,
Jul 24, 2006, 11:56:36 PM7/24/06
to
Hello, can someone please tell me if bit manipulation operators such
as AND, NOT, OR, SHL, SHR, are part of the ISO Modula-2 standard?


Cheers
Robert

Martin Whitaker

unread,
Jul 25, 2006, 7:11:15 PM7/25/06
to
Robert wrote:
> Hello, can someone please tell me if bit manipulation operators such
> as AND, NOT, OR, SHL, SHR, are part of the ISO Modula-2 standard?
>
Yes. Use a packedset type (such as the predefined type BITSET) along
with the standard set operators and the SHIFT and ROTATE functions
imported from the SYSTEM module, e.g.

VAR a, b, c : BITSET;

a = b * c; (* bitwise AND *)
a = b + c; (* bitwise OR *)
a = b / c; (* bitwise XOR *)
a = {} - b; (* bitwise NOT *)
a = SYSTEM.SHIFT(b,1); (* shift left by 1 *)
a = SYSTEM.SHIFT(b,-2); (* shift right by 2 *)
a = SYSTEM.ROTATE(b,1); (* rotate left by 1 *)
a = SYSTEM.ROTATE(b,-2); (* rotate right by 2 *)

You can declare your own bitset types, e.g.

TYPE Bitset8 = PACKEDSET OF (0..7);

although your compiler will probably place some restriction on
the maximum number of bits.

Martin

0 new messages