Page 252 - CTS - CSA TP - Volume 2
P. 252
COMPUTER SOFTWARE APPLICATION - CITS
TASK 3: Bitwise Operations
Code:
# Program to demonstrate bitwise operations based on precedence
a = int(input(“Enter an integer: “))
b = int(input(“Enter another integer: “))
result = (a & b) | (a ^ b)
print(“Result:”, result)
Explanation:
1 User Input:
• The program prompts the user to enter two integers (aandb).
2 Bitwise Operations:
• (a& b): Bitwise AND operation on a and b.
• (a ^ b): Bitwise XOR (exclusive OR) operation on a and b.
• (a & b) | (a ^ b): Bitwise OR operation on the results of the AND and XOR operations.
3 Result Display:
• The final result of the bitwise operations is stored in the variable result.
• The program prints the result to the console using print(“Result:”, result).
4 Operator Precedence:
• The & (AND) and ^ (XOR) operations have higher precedence than | (OR), so they are performed first.
5 Observation:
• Users can input integer values, and the program will demonstrate the bitwise AND, XOR, and OR operations
based on the precedence of these bitwise operators.
Output:
TASK 4: String Concatenation and Repetition
Code:
# Program to demonstrate string concatenation and repetition based on precedence
str1 = input(“Enter the first string: “)
str2 = input(“Enter the second string: “)
result = str1 + “ is “ * 3 + str2
print(“Result:”, result)
Explanation:
1 User Input:
• The program prompts the user to enter two strings (str1 and str2).
237
CITS : IT & ITES - Computer Software Application - Exercise 124