003-004-015
Bitwise Compound Assignment Operators
Medium
Problem Description
Bitwise Compound Assignment Operators
In this problem: You will create a program using bitwise compound assignment operators (>>=, <<=, &=, |=, ^=) to perform bit operations and output results.
Learning Objective: Understand bitwise compound assignment operators and the basics of bit shifting and logical operations
Overview
Bitwise compound assignment operators perform bit-level operations and assignment in one statement. <<= is left shift (multiply by power of 2), >>= is right shift (divide by power of 2), &= is bitwise AND, |= is bitwise OR, ^= is bitwise XOR.
Specifications
- Perform shift operations on a variable with initial value 8
<<=left shift by 2 bits (multiply by 4)>>=right shift by 1 bit (divide by 2)&=apply bit mask (0xFF)|=set bits^=toggle bits
Output Format
Start: 8
After <<= 2: 32
After >>= 1: 16
After &= 0xFF: 16
After |= 3: 19
After ^= 5: 22
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up