Questions C# Programming problem

JohnSnow

Well-known member
  • Mar 17, 2017
    8,697
    13,244
    113
    මේකට එන පිළිතුර මොකක්ද පැහැදිලි කිරීමකුත් අවශ්‍යයි :baffled::baffled:

    Suppose n is a variable of the type Byte and we wish to put OFF its fourth bit (from right) without disturbing any other bits. Which of the following statements will do this correctly?
    [A]. n = n && HF7
    [A]. n = n & 16
    [C]. n = n & 0xF7
    [D]. n = n & HexF7
    [E]. n = n & 8
     
    Last edited:

    JohnSnow

    Well-known member
  • Mar 17, 2017
    8,697
    13,244
    113
    Code:
    Correct answer is C. (assuming @ is a printing mistake)
    
    n        = abcd efgh
    0xF7     = 1111 0111
               ---------
    n & 0xF7 = abcd 0fgh
    
    By the observation that,
        x AND 1 = x
        x AND 0 = 0
    n = abcd efgh

    meka terun ne bn