Bird
0
0
DSA Cprogramming~30 mins

Bit Manipulation Basics AND OR XOR NOT Left Right Shift in DSA C - Build from Scratch

Choose your learning style9 modes available
Bit Manipulation Basics AND OR XOR NOT Left Right Shift
📖 Scenario: Imagine you are working with a simple device that stores settings as bits in a number. Each bit can be turned on or off to control different features. You want to learn how to change these bits using basic bit operations.
🎯 Goal: You will create a small C program that uses bit manipulation operators: AND, OR, XOR, NOT, left shift, and right shift. You will see how these operators change the bits of numbers step-by-step.
📋 What You'll Learn
Create two integer variables with exact values
Create a variable to hold the result of bit operations
Use bitwise AND, OR, XOR, NOT, left shift, and right shift operators
Print the results of each operation
💡 Why This Matters
🌍 Real World
Bit manipulation is used in low-level programming, device control, and performance optimization where direct control of bits is needed.
💼 Career
Understanding bitwise operations is important for embedded systems developers, systems programmers, and anyone working with hardware or performance-critical code.
Progress0 / 4 steps
1
Create two integer variables
Create two integer variables called a and b with values 12 and 5 respectively.
DSA C
Hint

Use int a = 12; and int b = 5; to create the variables.

2
Create a variable for results
Create an integer variable called result and set it to 0.
DSA C
Hint

Use int result = 0; to create the variable.

3
Apply bitwise operations
Use the variables a and b to perform these bitwise operations and store each result in result: AND, OR, XOR, NOT of a, left shift a by 2, and right shift b by 1. Write one line for each operation.
DSA C
Hint

Use & for AND, | for OR, ^ for XOR, ~ for NOT, << for left shift, and >> for right shift.

4
Print the results of each operation
Print the results of each bitwise operation in order: AND, OR, XOR, NOT of a, left shift a by 2, and right shift b by 1. Use printf with the format "%d\n" for each result.
DSA C
Hint

Use printf("%d\n", result); after each operation to print the result on a new line.