CompuServe Thread

Bits and Bytes

1 messages in this thread
#4510From: Richard BielakJan 3, 1989 9:29 PM
David, there are few simple ways of doing bit operations in Modula-2. For example to shift right, you divide by the appropriate power of two (i.e. k DIV 4 shifts right by two bits). A smart compiler will convert such statements to SHIFT instructions. To shift left, you multiply by the power of two. If you can't remember the constants needed for shifting, you can write them in hex (i.e. k * 010H shifts left by four bits). As far as logical operations: union, intersection, difference etc. operations on BITSETs are just the usual logical operations on bits. So you can write things like this, assuming "k" and "m" are CARDINALs: k := CARDINAL(BITSET(k)/BITSET(m)); This is k XOR m, in Modula-2. To turn a particular bit on you have to add a member to the bitset, to clear it remove it. I hope this gives you some idea on how to handle these things… …. Richie