4.1.19

Bitwise Manipulation - Masks

Test yourself on Bitwise Manipulation - Masks

Test your knowledge with free interactive questions on Seneca — used by over 10 million students.

Bitwise Manipulation - Masks

Bitwise manipulation is the act of modifying data by changing the bits within individual bytes.

Masks

Masks

  • Masks can be used with binary numbers to extract, set or toggle certain bits within a byte.
  • The following examples use the mask 1 1 1 1 0 0 0 0.
AND

AND

  • The AND operation extracts whichever bits of the byte correspond to the 1s in the mask. The bits that correspond to 0 are returned as 0.
  • For example, our AND mask extracts just the first four bits of a byte:
    • Original byte: 1 0 1 1 1 0 0 1
    • AND Mask: 1 1 1 1 0 0 0 0
    • Result: 1 0 1 1 0 0 0 0
OR

OR

  • The OR operation sets digits equal to 1 (for bits corresponding to the 1s in the mask) or leaves them unchanged (for bits corresponding to the 0s in the mask).
  • For example, our OR mask sets the first four bits of a byte to ‘1’:
    • Original byte: 1 0 1 1 1 0 0 1
    • OR Mask: 1 1 1 1 0 0 0 0
    • Result: 1 1 1 1 1 0 0 1
XOR

XOR

  • The XOR operation toggles binary digits (for bits corresponding to the 1s in the mask) or leave them unchanged (for bits corresponding to the 0s in the mask).
  • For example, our XOR mask toggles the first four bits of a byte:
    • Original byte: 1 0 1 1 1 0 0 1
    • XOR Mask: 1 1 1 1 0 0 0 0
    • Result: 0 1 0 0 1 0 0 1
Jump to other topics
1

Components of a Computer

2

Software & Software Development

3

Exchanging Data

4

Data Types, Data Structures & Algorithms

5

Legal, Moral, Cultural & Ethical Issues

6

Elements of Computational Thinking

6.1

Thinking Abstractly

6.2

Thinking Ahead

6.3

Thinking Procedurally

6.4

Thinking Logically

6.5

Thinking Concurrently

7

Problem Solving & Programming

8

Algorithms

Practice questions on Bitwise Manipulation - Masks

Can you answer these? Test yourself with free interactive practice on Seneca — used by over 10 million students.

  1. 1
  2. 2
  3. 3
Answer all questions on Bitwise Manipulation - Masks

Unlock your full potential with Seneca Premium

  • Unlimited access to 10,000+ open-ended exam questions

  • Mini-mock exams based on your study history

  • Unlock 800+ premium courses & e-books

Get started with Seneca Premium