Google Grup tidak lagi mendukung postingan atau langganan Usenet baru. Konten lama masih dapat dilihat.

Bit manipulation in ISO Modula-2

98 kali dilihat
Langsung ke pesan pertama yang belum dibaca

Robert

belum dibaca,
24 Jul 2006, 23.56.3624/07/06
kepada
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

belum dibaca,
25 Jul 2006, 19.11.1525/07/06
kepada
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 pesan baru