Grupos de Google ya no admite nuevas publicaciones ni suscripciones de Usenet. El contenido anterior sigue siendo visible.

Bit manipulation in ISO Modula-2

Visto 102 veces
Saltar al primer mensaje no leído

Robert

no leída,
24 jul 2006, 23:56:3624/7/06
a
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

no leída,
25 jul 2006, 19:11:1525/7/06
a
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 mensajes nuevos