[Gambas-user] Bitwise Operations Wish

Werner wdahn at ...1000...
Thu Sep 2 11:52:07 CEST 2010


There were days when binary values were actually represented in bits
within a byte or word. This is still true when interfacing to some boxes
such as PLCs.
Likewise, some operations - eg calculating a CRC - are very awkward to
implement without bitwise operations.

It would be really nice to have this functionality. Anyone who has ever
programmed in Assembler propably knows what I mean.

The following would be a fairly complete set, I think:

BitAnd( a AS Expression, b AS Expression) AS Expression
BitOr( a AS Expression, b AS Expression) AS Expression
BitXOr( a AS Expression, b AS Expression) AS Expression
BitNot( a AS Expression) AS Expression

BitShift( a AS Expression, count as Byte) AS Expression
BitRotate( a AS Expression, count as Byte) AS Expression

where Expression boils down to one of the following:
Byte
Short
Integer
Long

If expressions a and b are not the same size the shorter one needs to be
expanded with zeroes (MSB side) to match.

Regards
Werner






More information about the User mailing list