0
0
DSA Pythonprogramming~15 mins

Bit Manipulation Basics AND OR XOR NOT Left Right Shift in DSA Python - 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 electronic device that stores settings as numbers. Each setting is controlled by bits (0s and 1s). You want to learn how to change these bits using basic operations like AND, OR, XOR, NOT, and shifting bits left or right.
🎯 Goal: You will create a small program that shows how to use bit manipulation operations on two numbers. You will see how these operations change the bits and the resulting numbers.
📋 What You'll Learn
Create two integer variables with exact values
Create a variable for a bit shift amount
Use bitwise AND, OR, XOR, NOT, left shift, and right shift operations
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 roles in embedded systems, systems programming, and software development that requires efficient data handling.
Progress0 / 4 steps
1
Create two integer variables
Create two integer variables called num1 and num2 with values 12 and 5 respectively.
DSA Python
Hint

Use simple assignment to create num1 and num2 with the given numbers.

2
Create a variable for bit shift amount
Create an integer variable called shift and set it to 2.
DSA Python
Hint

Use simple assignment to create shift with the value 2.

3
Apply bitwise operations
Create variables to store the results of bitwise operations between num1 and num2: and_result for AND, or_result for OR, xor_result for XOR. Also create not_num1 for NOT of num1, left_shift for num1 shifted left by shift, and right_shift for num1 shifted right by shift.
DSA Python
Hint

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

4
Print the results
Print the values of and_result, or_result, xor_result, not_num1, left_shift, and right_shift each on its own line.
DSA Python
Hint

Use print() to show each result on its own line.