[Gambas-user] Bitwise Operations Wish
Benoît Minisini
gambas at ...1...
Thu Sep 2 14:06:30 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
-> a AND b
> BitOr( a AS Expression, b AS Expression) AS Expression
-> a OR b
> BitXOr( a AS Expression, b AS Expression) AS Expression
-> a XOR b
> BitNot( a AS Expression) AS Expression
-> NOT a
>
> BitShift( a AS Expression, count as Byte) AS Expression
-> Lsl(a, count)
-> Lsr(a, count)
-> Asl(a, count)
-> Asr(a, count)
> BitRotate( a AS Expression, count as Byte) AS Expression
-> Rol(a, count)
-> Ror(a, count)
>
> 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.
That is what they do.
Regards,
--
Benoît Minisini
More information about the User
mailing list