Session 6 - Binary Numbers and Bitwise Operators Flashcards
Binary Numbers and Bitwise Operators (17 cards)
Bitwise AND (2mins)
Find the result of ANDing two numbers
Input:
Enter two numbers: 5 3
Output:
Bitwise AND: 1
A
Bitwise OR (2mins)
Find the result of ORing two numbers
Input:
Enter two numbers: 5 3
Output:
Bitwise OR: 7
A
Bitwise XOR (2mins)
Find the result of XORing two numbers
Input:
Enter two numbers: 5 3
Output:
Bitwise XOR: 6
A
Bitwise NOT (2mins)
Invert the bits of a number
Input:
Enter a number: 5
Output:
Bitwise NOT: -6
A
Left Shift (2mins)
Shift bits to the left by 1
Input:
Enter a number: 5
Output:
Left Shift: 10
A
Right Shift (2mins)
Shift bits to the right by 1
Input:
Enter a number: 5
Output:
Right Shift: 2
A
Decimal to Binary (2mins)
Convert a Number to Binary
Input:
Enter a number: 10
Output:
Binary: 1010
A
Binary to Decimal (2mins)
Print the decimal representation of the binary input
Input:
Enter a binary number: 1101
Output:
Decimal: 13
A
Binary print (2mins)
Print All Numbers from Range x to y in Binary Form
Input:
Enter start and end numbers: 5 10
Output:
5 -> 101
6 -> 110
7 -> 111
8 -> 1000
9 -> 1001
10 -> 1010
A
Binary 0s (2mins)
Count the Number of 0s in the Binary Form
Input:
Enter a number: 18
Output:
Binary: 10010
Count of 0s: 3
A
Binary 1s (2mins)
Count the Number of 1s in the Binary Form
Input:
Enter a number: 15
Output:
Binary: 1111
Count of 1s: 4
A
Binary 2n (2mins)
Check if a Number is a Power of Two (Using Binary)
Input:
Enter a number: 8
Output:
Yes, it’s a power of 2
A
Reverse Binary (2mins)
Reverse the Binary of a Number and Convert Back to Decimal
Input:
Enter a number: 13
Output:
Binary: 1101
Reversed Binary: 1011
Decimal of Reversed: 11
A
Toggle Bits using XOR (3mins)
Flip (invert) all bits of a number up to the most significant bit.
Hint: XOR with a mask of all 1s (same bit-length as the number).
Input:
Enter a number: 10
Output:
Binary: 1010
Toggled: 0101
Decimal: 5
A
Set Bits checker (3mins)
Write a program to compare if two numbers have the same number of 1s in their binary representation.
Input:
Enter two numbers: 7 11
Output:
7 → 111
11 → 1011
Same number of set bits: Yes
A
Binary Palindrome (3mins)
Check if the binary representation of a number is a palindrome.
Input:
Enter a number: 9
Output:
Binary: 1001
Is Palindrome: Yes
A
Bitwise AND of Range (3mins)
Given two numbers a and b, print the result of bitwise AND for every number in the range [a, b].
Note: 5 = 101, 6 = 110, 7 = 111 → 101 & 110 & 111 = 100
Input:
Enter two numbers: 5 7
Output:
Binary AND from 5 to 7 = 4
A