Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   help on masking (http://www.go4expert.com/forums/help-on-masking-t1748/)

hapa_at_1 29Oct2006 00:16

help on masking
 
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

shabbir 29Oct2006 10:43

Re: help on masking
 
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.


All times are GMT +5.5. The time now is 20:23.