Hello Charles,

On Friday, April 2, 2004 at 6:21:55 AM you wrote (at least in part):

>>> I hope this isn't some kind of bitmasking thing, because that just
>>> makes my head spin.
>> That is exactly what it is...

> So how does one deal with that?


> How does this work?



OK, an example: PW_GID is set to 44 (0x2C), that's 0x04 + 0x08 + 0x20,

To figure if the user is set to NO_DIALUP check:

PW_GID & 64 (0x40 for NO_DIALUP):

  44 &   64 = 0
0x2C & 0x40 = 0

Or in binary notation:
& 01000000
  00000000 = 0x00 == 0 decimal.

So this user has not NO_DIALUP set.

No imagine a user set to NO_DIALUP, NO_WEBMAIL and NO_RELAY:

0x04 + 0x20 + 0x40 = 0x64
   4 +   32 +   64 =  100 (decimal)

PW_GID & 64 (0x40 for NO_DIALUP):

 100 &   64 =   64 (decimal)
0x64 & 0x40 = 0x40

& 01000000
  01000000 = 0x40 == 64 decimal.

So to see if a flag is set AND operate on PW_GID and FLAG and see if
the result is different from zero. As every flag gets a different bit
assigned this bit, and only this bit, will be set when you AND operate
and this bit was set in PW_GID's value.

In cat it is really quite easy to handle and most programming
languages should be able to bit-operate with integer values too. So
you wouldn't even have to convert PW_GID into a "real bitmask", in
fact the integer already is one: just use an arbitrary calculator to
translate an arbitrary decimal value into binary representation.
No "translate" all the hex values for different flags into binary and
you'll see: they all have /exactly/ one bit set to 1. Not more, not
less. And this is all about how it works :-)

Best regards
Peter Palmreuther

Once a job is fouled up, anything done to improve it only makes it

Reply via email to