1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

help on masking

Discussion in 'C' started by hapa_at_1, Oct 28, 2006.

  1. hapa_at_1

    hapa_at_1 New Member

    how does masking works in c++
    how can i extract the position of my desire from a series of bits given to me

    for instance if

    16 in bit is

    10000
    how can i get the 3rd number
    please adivce
     
  2. shabbir

    shabbir Administrator Staff Member

    You need to do the Bitwise AND (&) / Bitwise OR (|) to do the masking

    Truth table is as follows
    OR
    Code:
    +-----+-----+-----+
    | OP1 | OP2 | O/P |
    +-----+-----+-----+
    |  0  |  0  |  0  |
    |  0  |  1  |  1  |
    |  1  |  0  |  1  |
    |  1  |  1  |  1  |
    +-----+-----+-----+
    
    AND
    Code:
    +-----+-----+-----+
    | OP1 | OP2 | O/P |
    +-----+-----+-----+
    |  0  |  0  |  0  |
    |  0  |  1  |  0  |
    |  1  |  0  |  0  |
    |  1  |  1  |  1  |
    +-----+-----+-----+
    
    Or it with all Zeros and you get the the masked digit or AND it with 1.
     

Share This Page