Bitwise operations

0

Category :

Bitwise operations........some craic!!
----------------------

int test1 = 3; // binary: 0011
int test2 = 2 // binary: 0010
int flagTest = test1 | test2; // binary result: 0011 | 0010 = 0011

0011
0010 OR
----
0011

flagTest = 8; // 1000
flagTest |= 3; // 2 = 0011
// flagTest is now binary 1011

AutoApprovalFails fails = AutoApprovalFails.Success;

// this ngb/coach level is disabled
fails |= AutoApprovalFails.HasTutorsInTraining;

fails |= AutoApprovalFails.InvalidCourseLevel;

string message = string.Empty;
foreach (Enum value in Enum.GetValues(typeof(AutoApprovalFails)))
{
    // eg, if 0100 in 1110;  0100 & 0111 = 0100
    if (((AutoApprovalFails)value & fails) == (AutoApprovalFails)value)
    {
        message += EnumDescriptor.GetDescription((AutoApprovalFails)value);
    }
}

0 comments:

Post a Comment