Hi everybody,
I have program which takes some value from a database (active directory, attribute UserAccountControl more info:
http://msdn.microsoft.com/en-us/library/ms680832(v=vs.85).aspx) which contains many different things coded as a bitmask. Most common values are 512 for a 'normal' user and 514 for 'disabled' user. I need to know if this user account is active or disabled. I know this value is corresponds to a bit number two e.g. if the value matches 000000
10 this account is disabled and in case it matches 000000
00 this account is enabled. I followed some discussions here but still not sure how to do this kind of calculation in right way :-((
I managed to get right output using the & operator $bitmask_value & 2, see example code:
use strict;
use warnings;
my @bitmask_value = ( 512, 514, 210, 328, 2, 1, 65535 );
foreach my $bitmask_value ( @bitmask_value ) {
print 'bit 2 is ', $bitmask_value & 2 ? 'set' : 'not set', " for v
+alue [$bitmask]\n";
}
could you please tell me if there is some major problem or if I can trust this code? thank yo in advance
In reply to bitmask check
by wwe
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.