[C#] Question about an old thread

Discussion in 'Mixed Languages' started by Kern, Apr 23, 2013.

Tags:
  1. Kern

    Kern MDL Novice

    Apr 23, 2013
    2
    0
    0
    #1 Kern, Apr 23, 2013
    Last edited by a moderator: Apr 20, 2017
    I have a question about an old thread:
    Code:
    forums.mydigitallife.net/threads/35723-C-Compatible-Windows-8-Product-Key-Decoder
    First of all, the code in that thread works correctly, I'm not disputing that.

    My question is about these two lines:
    Code:
                // Check if Windows 8/Office 2013 Style Key (Can  contain the letter "N")
                int containsN = (digitalProductId[keyStartIndex + 14]  >> 3) & 1;
                digitalProductId[keyStartIndex + 14] =  (byte)((digitalProductId[keyStartIndex + 14] & 0xF7) | ((containsN  & 2) << 2));
    Or in a simplified form:
    Code:
     
    byte b = ..;
    int containsN = (b  >> 3) & 1;
    b =  (byte)((b & 0xF7) | ((containsN  & 2) << 2));
    First (b >> 3) & 1 checks whether the 4th bit in b is set.
    Then b = b & 0xF7 sets the 4th bit to 0

    But what is the meaning of | ((containsN & 2) << 2) ?
    containsN is either 1 or 0.
    1&2=0 and 0&2=0
    0<<2 = 0
    x|0 = x

    So this piece seems to have no meaning? I could be wrong or I could be missing something, but this has been bothering me for some time now so if someone could clarify that would be great.

    Thanks
     
  2. Muerto

    Muerto MDL Debugger

    Mar 7, 2012
    1,858
    2,115
    60
    #2 Muerto, Apr 23, 2013
    Last edited: Aug 22, 2021
    ...
     
  3. Kern

    Kern MDL Novice

    Apr 23, 2013
    2
    0
    0
    I know what ContainsN is for, I'm just confused about the meaning of | ((containsN & 2) << 2) . It seems to me that this part has no effect on the value of b.