of the variable a (before the evaluation), which Bit() has to *figure out* first:
Code: Select all
#define Bit( value, bit_number ) (((value) and (Cast(TypeOf(value), 1) shl (bit_number))) <> 0)
Code: Select all
#define Bit( value, bit_number ) (((value) and (Cast(TypeOf(value), 1) shl (bit_number))) <> 0)
Value could be a U/Byte / U/Short ... The explicit cast prevents n, being larger than allowed, by type-of-var's size,fxm wrote:I do not see the interest of an explicit casting in this kind of macro as Bit, BitSet, BitReset.
fxm wrote:The implicit compiler casting is sufficient.
Code: Select all
#Undef Bit
#Define Bit(value, bit_number) ( ( (value) and (1 shl (bit_number)) ) <> 0 )
Dim As Byte b = &h80
Dim As Short s = &h7FFF
Dim As ULongInt u = &h800FFFFFFFFFF000
? Bit(b, 8), Bit(s, 15), Bit(u, 37) ' test on u = 0 (wrong result, bit is set)
Sleep