tags:

views:

830

answers:

3

I am reading a list of assigned rights from an exchange mailbox, these values are returned via the AccessFlag property which returns 20001 in Hex, it looks like 2000 represents the READ permission and the 1 represents FULL permission.

What I want to do is display that value as READ & FULL permissions set.

A: 

You could use the bitwise XOR operator to filter out the values you need and deduce the permission set from them.

Bartek Tatkowski
+7  A: 

If you want is as a string, you need an enum.

So if you have something like this:

[Flags]
enum Permissions
{
  Read = 0x20000,
  Full = 0x00001
}

Then you can cast your return value and use ToString()

string val = ((Permissions )myValue).ToString();

And it will come out something like this:

Read, Full

Note that the Flags attribute is important for this type of enum.

ctacke
+1 for Flags enums!
Daniel Schaffer
You missed the () on your ToString() call in your code snippet.
Daniel Schaffer
+1: Lovely trick :) It shows "Read, Full" for me (I had to try it out)
Binary Worrier
Thanks that is a really nice solution.
+3  A: 

To be honest I'm not sure what you're asking for.

If you have a value from the AccessFlag, and you want to see if it has either of those flag, you can use a bitwise and e.g.

If((accessFlag & 0x2000) != 0) // It has FULL
If((accessFlag & 0x1) != 0) // It has READ
If((accessFlag & 0x2001) != 0) // It has READ AND FULL

Is this what you're looking for?

Binary Worrier