What Are Bitwise Operators in C?
Bitwise operators perform operations directly on the binary representation of integers. Instead of working with decimal values, these operators manipulate individual bits, making them highly efficient for low-level programming.
The main bitwise operators in C are:
- AND (&)
- OR (|)
- XOR (^)
- NOT (~)
- Left Shift (<<)
- Right Shift (>>)
These operators are widely used in bit manipulation interview questions and answers, especially in embedded systems, firmware development, and performance-critical applications.
Basic Bitwise Operators in C Interview Questions and Answers for Freshers
This section covers commonly asked c bitwise interview questions for freshers, focusing on core concepts and understanding.
1. What is a bitwise AND operator in C?
The bitwise AND (&) operator compares each bit of two integers. It returns 1 only if both corresponding bits are 1; otherwise, it returns 0.
Example:
5 = 101
3 = 011
Result = 001 (1)
2. What is the difference between & and && in C?
This is one of the most important bitwise operators in C interview questions and answers.
- & is a bitwise operator that works at the binary level
- && is a logical operator used in conditional expressions
Using & instead of && in conditions is a common mistake.
3. What does the bitwise OR (|) operator do?
The OR operator compares each bit and returns 1 if at least one of the bits is 1.
Example:
5 = 101
3 = 011
Result = 111 (7)
4. What is the XOR (^) operator in C?
The XOR operator returns 1 when the bits are different and 0 when they are the same. It is widely used in bitwise operators examples in C and in swapping logic.
5. What is bitwise NOT (~) in C?
The NOT operator inverts all bits of a number (1 becomes 0 and 0 becomes 1). It works using two’s complement representation.
Example:
~5 = -6
This is a frequently asked concept in most asked bitwise questions in C.
6. What is the left shift (<<) operator?
The left shift operator shifts all bits to the left by a specified number of positions. Each shift effectively multiplies the number by 2.
Example:
5 << 1 = 10
7. What is the right shift (>>) operator?
The right shift operator shifts bits to the right. Each shift generally divides the number by 2 (for positive numbers).
Example:
8 >> 2 = 2
8. Why are bitwise operators faster than arithmetic operations?
Bitwise operations work directly at the binary level and are processed faster by the CPU. This is why they are widely used in bit manipulation interview questions and answers and embedded applications.
9. Can bitwise operators be applied to float or double data types?
No, bitwise operators can only be applied to integer data types such as int, char, and long.
10. Where are bitwise operators used in real-world applications?
Bitwise operators are commonly used in:
- Embedded systems for register manipulation
- Device drivers and hardware control
- Data compression and encryption
- Efficient memory usage
This is a practical question often included in bitwise operators in embedded C interview questions.

Bitwise Operator Output Questions in C
These are important bitwise operator output questions in C asked in interviews, especially in tricky bitwise questions in C interview rounds.
11.
int x = 7 & 4;
printf("%d", x);
Output: 4
12.
int x = 7 | 4;
printf("%d", x);
Output: 7
13.
int x = 7 ^ 4;
printf("%d", x);
Output: 3
14.
int x = ~5;
printf("%d", x);
Output: -6
15.
int x = 10 << 2;
printf("%d", x);
Output: 40
16.
int x = 10 >> 1;
printf("%d", x);
Output: 5
17.
int x = (5 & 3) | 2;
printf("%d", x);
Output: 3
18.
int x = 5 & (3 | 2);
printf("%d", x);
Output: 1
19.
int x = 4 ^ 4;
printf("%d", x);
Output: 0
20.
int x = 6 & 1;
printf("%d", x);
Output: 0
21.
int x = 6 | 1;
printf("%d", x);
Output: 7
22.
int x = 6 ^ 1;
printf("%d", x);
Output: 7
23.
int x = (8 >> 1) << 1;
printf("%d", x);
Output: 8
24.
int x = (3 << 2) + 1;
printf("%d", x);
Output: 13
25.
int x = ~0;
printf("%d", x);
Output: -1
26.
int x = (1 << 3) | 2;
printf("%d", x);
Output: 10
27.
int x = (1 << 4) & 8;
printf("%d", x);
Output: 0
28.
int x = (2 << 2) ^ 3;
printf("%d", x);
Output: 11
29.
int x = (5 ^ 2) & 3;
printf("%d", x);
Output: 3
30.
int x = (7 & 3) << 1;
printf("%d", x);
Output: 6
These questions are frequently asked in:
- bitwise operators in C interview questions and answers
- tricky bitwise questions in C interview
- bit manipulation interview questions and answers
They help interviewers evaluate:
- Binary understanding
- Operator precedence
- Real problem-solving ability

Bitwise Programming Interview Questions (Easy to Advanced)
This section covers bitwise programming interview questions that test coding ability, optimization skills, and understanding of bit manipulation to reduce time complexity. These are frequently asked in product-based companies and Amazon-level interviews.
31. Swap two numbers without using a temporary variable
a = a ^ b;
b = a ^ b;
a = a ^ b;
This works because XOR cancels out identical bits. It avoids extra memory usage and is a classic bit manipulation interview question.
32. Check if a number is even or odd
if (n & 1)
printf("Odd");
else
printf("Even");
The least significant bit determines parity. If it is 1, the number is odd; otherwise, it is even. This is faster than using modulo.
33. Set the k-th bit of a number
n = n | (1 << k);
This sets the k-th bit to 1 without affecting other bits. Commonly used in bitwise operators programs in C interview questions.
34. Clear the k-th bit of a number
n = n & ~(1 << k);
This clears the k-th bit by using a mask with all bits set except the target bit.
35. Toggle the k-th bit
n = n ^ (1 << k);
XOR flips the selected bit. If it is 1, it becomes 0, and vice versa.
36. Check if k-th bit is set or not
if (n & (1 << k))
printf("Set");
else
printf("Not Set");
This checks whether a specific bit is 1. Frequently asked in bitwise programming interview questions.
37. Count number of set bits (basic method)
int count = 0;
while (n) {
if (n & 1) count++;
n >>= 1;
}
This checks each bit one by one. Time complexity is O(number of bits).
38. Count set bits (optimized method)
int count = 0;
while (n) {
n = n & (n - 1);
count++;
}
This removes the lowest set bit in each iteration. It is faster and commonly asked in Amazon-level interviews.
39. Check if a number is power of 2
if (n > 0 && (n & (n - 1)) == 0)
printf("Power of 2");
A power of 2 has only one set bit. This method is efficient and avoids loops.
40. Remove the lowest set bit
n = n & (n - 1);
This clears the rightmost set bit. It is widely used in optimized algorithms and bit manipulation interview questions.
41. Find the only non-repeating element in an array
int res = 0;
for (int i = 0; i < n; i++)
res ^= arr[i];
XOR of a number with itself is 0, and with 0 is the number itself. All repeating elements cancel out, leaving only the unique element. This is a standard bit manipulation interview question with O(n) time and O(1) space.
42. Find two non-repeating elements in an array
// Step 1: XOR all elements
// Step 2: Find rightmost set bit
// Step 3: Divide elements into two groups and XOR separately
This is an advanced variation of XOR problems and is commonly asked in Amazon-level interviews. It uses grouping based on a set bit to separate the two unique numbers.
43. Find missing number from 1 to n
int res = 0;
for (int i = 1; i <= n; i++)
res ^= i;
for (int i = 0; i < n-1; i++)
res ^= arr[i];
By XORing all numbers from 1 to n and the array elements, the missing number remains. This avoids sorting or extra memory.
44. Reverse bits of a number
int rev = 0;
for (int i = 0; i < 32; i++) {
rev <<= 1; rev |= (n & 1); n >>= 1;
}
Each bit is extracted and appended in reverse order. This is useful in low-level programming and data processing.
45. Check if binary representation is palindrome
// Reverse bits and compare with original
This problem checks whether the binary form of a number reads the same forwards and backwards. It combines bit reversal logic with comparison.
46. Find position of only set bit
int pos = 1;
while (!(n & 1)) {
n >>= 1;
pos++;
}
This assumes only one bit is set. It shifts right until it finds the set bit. Common in embedded and firmware interviews.
47. Multiply a number by 2 using bitwise
n = n << 1;
Left shift multiplies the number by 2. This is faster than arithmetic multiplication and used in optimized code.
48. Divide a number by 2 using bitwise
n = n >> 1;
Right shift divides the number by 2 for positive integers. This is commonly used in performance-critical applications.
49. Find absolute value using bitwise
int mask = n >> 31;
int res = (n + mask) ^ mask;
This removes the sign without using conditional statements. It is a common trick in bitwise operators programs in C interview questions.
50. Add two numbers without using + operator
while (b != 0) {
int carry = a & b;
a = a ^ b;
b = carry << 1;
}
This uses XOR for addition and AND for carry. It is a classic Amazon-level bit manipulation problem and demonstrates deep understanding of binary arithmetic.
This completes a strong set of bitwise programming interview questions covering:
- Basic operations
- Optimization techniques
- Real interview problems
- Amazon-level logic
Tricky Bitwise Questions in C Interview
What is the result of ~5?
Answer: -6 (based on 2’s complement)
What happens when shifting negative numbers?
It depends on the compiler and system architecture. This is often asked in real interview questions on bitwise operators in C.
Can bitwise operators be applied to float?
No, they are applicable only to integer data types.
Bit Manipulation Interview Questions and Answers
How to check if a number is a power of 2?
if ((n & (n - 1)) == 0)
How to remove the lowest set bit?
n = n & (n - 1);
How to count set bits?
Using loops or optimized approaches. These are frequently asked in most asked bitwise questions in C.
C Bitwise Operators Tricks Interview
These c bitwise operators tricks interview concepts are very useful:
- n & (n – 1) removes the lowest set bit
- n << 1 multiplies a number by 2
- n >> 1 divides a number by 2
- XOR can be used to swap values
These tricks are often included in tricky bitwise questions in C interview.
Bitwise Operators in Embedded C Interview Questions
This section focuses on bitwise operators in embedded C interview questions.
Why are bitwise operators used in embedded systems?
They are used for:
- Register manipulation
- Bit masking
- Hardware-level control
What is bit masking?
Bit masking is used to extract or modify specific bits in a register.
Example
PORTA |= (1 << 2);
This sets a specific bit high.
Most Asked Bitwise Questions in C
- Swap numbers using XOR
- Check even or odd using bitwise
- Predict output of expressions
- Set, clear, and toggle bits
- Power of 2 check
These are frequently asked across interviews.
Final Thoughts
Bitwise operators are essential for solving low-level programming problems and are widely used in embedded systems and firmware roles.
To perform well in interviews:
- Practice output-based questions
- Understand bit manipulation logic
- Focus on real-world applications
Mastering these topics will help you confidently answer bitwise operators in C interview questions in any technical interview.
