Session 6 - Binary Numbers and Bitwise Operators Flashcards

Binary Numbers and Bitwise Operators (17 cards)

1
Q

Bitwise AND (2mins)

Find the result of ANDing two numbers

Input:
Enter two numbers: 5 3

Output:
Bitwise AND: 1

A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Bitwise OR (2mins)

Find the result of ORing two numbers

Input:
Enter two numbers: 5 3

Output:
Bitwise OR: 7

A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Bitwise XOR (2mins)

Find the result of XORing two numbers

Input:
Enter two numbers: 5 3

Output:
Bitwise XOR: 6

A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Bitwise NOT (2mins)

Invert the bits of a number

Input:
Enter a number: 5

Output:
Bitwise NOT: -6

A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Left Shift (2mins)

Shift bits to the left by 1

Input:
Enter a number: 5

Output:
Left Shift: 10

A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Right Shift (2mins)

Shift bits to the right by 1

Input:
Enter a number: 5

Output:
Right Shift: 2

A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Decimal to Binary (2mins)

Convert a Number to Binary

Input:
Enter a number: 10

Output:
Binary: 1010

A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Binary to Decimal (2mins)

Print the decimal representation of the binary input

Input:
Enter a binary number: 1101

Output:
Decimal: 13

A

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

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

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

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

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

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

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

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

A

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

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

17
Q

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