Masks and Their Construction

Creating mask values

Suppose n = 45 and your task is to:

  • AND it with a number whose 3rd bit is on
  • OR it with a number whose 7th bit is on
  • XOR it with a number whose 4th bit is on

The original number is n; the second operand is known as a mask. Here, we intend to learn how to create mask values.

Example program 1: Creating mask values using a hexadecimal number

See the code given below!

Get hands-on with 1200+ tech skills courses.