Jamie schrieb:
>> if (7 and x)=5 then showmessage('true');
> That is a logical AND..
Not exactly. It's a *bitwise* (arithmetic) AND, not a logical (boolean)
one. The result is an integral (ordinal) value, not a boolean one. This
difference may have confused the OP.
> 7 = 111 in binary
> 5 = 101 in binary
In addition to your explanation of bit manipulation, one also can think
in SETs, where a byte is equivalent to an
type
Toctet = set of 0..7;
....
TDWORD = set of 0..31;
and the above values correspond to
const
sept = [1,2,4]; //1+2+4 = 7
cinq = [1,4]; //1 + 4 = 5
Then SET operations can be used for testing, setting and clearing bits:
set becomes Include()
clr becomes Exclude()
OR becomes + (union)
AND becomes * (intersection)
XOR becomes - (difference)
....
[just from memory, please check the set operators in online help]
Using sets can result in more transparent handling of bitmasks, e.g. in
API calls. Unfortunately the C language has enums, but no equivalent for
sets, so that overloaded versions of the API functions were required, or
typecasts, for passing sets as integral values :-(
DoDi


|