domingo, 13 de fevereiro de 2011

Bitwise Operator

Será que o cara que escreveu este código esqueceu que existem operadores Bitwise???
    public bool IsFileReadOnly(int attributes)
    {
        bool retVal = false;

        if (attributes > 63)
        {
            attributes = attributes - 63;
        }

        if (attributes > 32)
        {
            attributes = attributes - 32;
        } 

        if (attributes > 16)
        {
            attributes = attributes - 16;
        }

        if (attributes > 8)
        {
            attributes = attributes - 8;
        }

        if (attributes > 4)
        {
             attributes = attributes - 4;
        }

        if (attributes > 2)
        {
            attributes = attributes - 2;
        }
  
        if (attributes  == 1)
        {
            retVal = true;
        }

        return retVal;
    }

Nenhum comentário:

Postar um comentário