Hexadecimals and System.Int32

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am a newbie to .NET, but not to programming.

I am taking in Active Directory users using the DirectoryServices namespace
(getting results from a DirectorySearcher). One of the attributes I am
getting is the UserAccountControl attribute that AD stores as a hex.

However, when I look in my search result, that information is typed as a
System.Int32. I am trying to determine if a user is disabled, which will
force a '2' in the last character of the hex string (0X00000002).

Is there any way to either keep the attribute in hex format or change it back?

Thanks.
 
Joe said:
I am a newbie to .NET, but not to programming.

I am taking in Active Directory users using the DirectoryServices namespace
(getting results from a DirectorySearcher). One of the attributes I am
getting is the UserAccountControl attribute that AD stores as a hex.

However, when I look in my search result, that information is typed as a
System.Int32. I am trying to determine if a user is disabled, which will
force a '2' in the last character of the hex string (0X00000002).

Is there any way to either keep the attribute in hex format or change it back?

The easiest test would be:

if ((value & 0xf)==2)
{
....
}

(That should work for all positive numbers - I haven't stopped to think
about negative ones, but you probably should.)
 
Jon Skeet said:
The easiest test would be:

if ((value & 0xf)==2)
{
....
}

(That should work for all positive numbers - I haven't stopped to think
about negative ones, but you probably should.)

Jon:

Thanks for the info. I think I will try it.

I solved it myself a little bit ago, but your way might be more efficient.
Here is the way I am doing it...

1) Convert Int32 back to Hex: UACHex = String.Format("{0:x}", UACInt)
2) Get last character and compare to '2': if
(UACHex.Substring(UACHex.Length-1,1) == '"2")

Once again, thanks.

Joe
 
Joe said:
Thanks for the info. I think I will try it.

I solved it myself a little bit ago, but your way might be more efficient.

It certainly will be :)
Here is the way I am doing it...

1) Convert Int32 back to Hex: UACHex = String.Format("{0:x}", UACInt)
2) Get last character and compare to '2': if
(UACHex.Substring(UACHex.Length-1,1) == '"2")

Even doing the string conversion way, there's no need to create a new
substring. For instance:

string x = UACInt.ToString("x");
if (x.EndsWith("2"))
or
if (x[x.Length-1]=='2')
 
Back
Top