Take FREE!! Online Cocubes Mock Test to Crack various Companies Written Exams.
Practice List of Paytm Coding Questions !!!
Take 30+ FREE!! Online Arithmetic Aptitude Mock test to crack any Exams.
Technical Discussion :: C
Home > Technical Interview Q&A > C > Discussion

10 / 123

# What is meant by "bit masking"?

Bitmasking refers to the technique of representing a subset of a set using bits of a number .
for eg suppose we have n numbers {1,2,3,4,5,6,7,8} in an array

then a bitmask to indicate the subset{2,3,6} of the above set will be a set of binary values like {0,1,1,0,0,1,0,0} where 1 indicates element at ith index belong to set and 0 indicated that it doesnt.

this 0,1 information can also be stored in bits of a number.

for eg consider a number mask=0;

if we want to set the ith bit of mask to 1 we can apply following operation

where '|' is bitwise or and '<<' is bitwise left shift operator
and the ith bit will become 1 indicating the number is included in the set
similarly to remove a number from the set following operating can be performed

Rate This: +0 -0