Practice 50 JavaScript Bit Manipulation Programming Questions, TechnoVlogs

Practice 50 JavaScript Bit Manipulation Programming Questions


Q1. Write a JavaScript program to check if a number is even or odd using bitwise operators.  
Input: num = 5  
Expected Output: odd

Q2. Write a JavaScript program to toggle the ith bit of a number.  
Input: num = 5, i = 1  
Expected Output: 7

Q3. Write a JavaScript program to check if the ith bit of a number is set (1) or not (0).  
Input: num = 5, i = 1  
Expected Output: true

Q4. Write a JavaScript program to turn off the ith bit of a number.  
Input: num = 5, i = 2  
Expected Output: 1

Q5. Write a JavaScript program to turn on the ith bit of a number.  
Input: num = 5, i = 1  
Expected Output: 7

Q6. Write a JavaScript program to count the number of set bits (1's) in a number.  
Input: num = 5  
Expected Output: 2

Q7. Write a JavaScript program to find the position of the most significant set bit in a number.  
Input: num = 18  
Expected Output: 4

Q8. Write a JavaScript program to find the position of the least significant set bit in a number.  
Input: num = 18  
Expected Output: 1

Q9. Write a JavaScript program to swap two numbers using bitwise XOR.  
Input: a = 5, b = 7  
Expected Output: a = 7, b = 5

Q10. Write a JavaScript program to check if a number is a power of 2 using bitwise operators.  
Input: num = 16  
Expected Output: true

Q11. Write a JavaScript program to set the nth bit of a number to 0.  
Input: num = 7, n = 1  
Expected Output: 5

Q12. Write a JavaScript program to check if two numbers have the same parity (both even or both odd) using bitwise operators.  
Input: a = 4, b = 6  
Expected Output: true

Q13. Write a JavaScript program to get the nth bit of a number.  
Input: num = 5, n = 1  
Expected Output: 1

Q14. Write a JavaScript program to check if a number is divisible by 3 using bitwise operators.  
Input: num = 9  
Expected Output: true

Q15. Write a JavaScript program to multiply a number by 2 using bitwise left shift.  
Input: num = 4  
Expected Output: 8

Q16. Write a JavaScript program to divide a number by 2 using bitwise right shift.  
Input: num = 4  
Expected Output: 2

Q17. Write a JavaScript program to reverse the bits of a number.  
Input: num = 5  
Expected Output: 2684354560

Q18. Write a JavaScript program to perform a bitwise AND operation between two numbers.  
Input: num1 = 5, num2 = 3  
Expected Output: 1

Q19. Write a JavaScript program to perform a bitwise OR operation between two numbers.  
Input: num1 = 5, num2 = 3  
Expected Output: 7

Q20. Write a JavaScript program to perform a bitwise XOR operation between two numbers.  
Input: num1 = 5, num2 = 3  
Expected Output: 6

Q21. Write a JavaScript program to check if a number is a non-negative integer using bitwise operators.  
Input: num = -5  
Expected Output: false

Q22. Write a JavaScript program to clear the least significant bit of a number.  
Input: num = 6  
Expected Output: 4

Q23. Write a JavaScript program to check if the least significant bit of a number is set to 1.  
Input: num = 5  
Expected Output: true

Q24. Write a JavaScript program to count the number of 0's in the binary representation of a number.  
Input: num = 5  
Expected Output: 3

Q25. Write a JavaScript program to set all bits of a number to 1.  
Input: num = 5  
Expected Output: 7

Q26. Write a JavaScript program to get the binary representation of a number.  
Input: num = 5  
Expected Output: 101

Q27. Write a JavaScript program to toggle all bits of a number.  
Input: num = 5  
Expected Output: -6

Q28. Write a JavaScript program to check if a number has an odd number of 1's in its binary representation.  
Input: num = 5  
Expected Output: true

Q29. Write a JavaScript program to check if the binary representation of a number contains only one 1.  
Input: num = 8  
Expected Output: true

Q30. Write a JavaScript program to check if the number is a multiple of 4 using bitwise operators.  
Input: num = 8  
Expected Output: true

Q31. Write a JavaScript program to perform a bitwise NOT operation on a number.  
Input: num = 5  
Expected Output: -6

Q32. Write a JavaScript program to check if two numbers are equal using bitwise operators.  
Input: num1 = 5, num2 = 5  
Expected Output: true

Q33. Write a JavaScript program to count the number of bits needed to convert one number to another.  
Input: num1 = 5, num2 = 9  
Expected Output: 2

Q34. Write a JavaScript program to calculate the number of bits required to store a number.  
Input: num = 5  
Expected Output: 3

Q35. Write a JavaScript program to find the bitwise AND of all numbers in a range.  
Input: num1 = 5, num2 = 7  
Expected Output: 4

Q36. Write a JavaScript program to find the bitwise OR of all numbers in a range.  
Input: num1 = 5, num2 = 7  
Expected Output: 7

Q37. Write a JavaScript program to find the bitwise XOR of all numbers in a range.  
Input: num1 = 5, num2 = 7  
Expected Output: 2

Q38. Write a JavaScript program to clear the kth bit of a number.  
Input: num = 7, k = 1  
Expected Output: 5

Q39. Write a JavaScript program to check if the binary representation of a number has exactly two 1's.  
Input: num = 6  
Expected Output: true

Q40. Write a JavaScript program to find the number of trailing 0's in the binary representation of a number.  
Input: num = 8  
Expected Output: 3

Q41. Write a JavaScript program to check if a number is a power of 4 using bitwise operators.  
Input: num = 16  
Expected Output: true

Q42. Write a JavaScript program to find the two's complement of a number.  
Input: num = 5  
Expected Output: -5

Q43. Write a JavaScript program to check if a number is negative using bitwise operators.  
Input: num = -5  
Expected Output: true

Q44. Write a JavaScript program to determine if a number has an odd or even number of 1's in its binary representation.  
Input: num = 7  
Expected Output: odd

Q45. Write a JavaScript program to check if a number is divisible by 2 using bitwise operators.  
Input: num = 4  
Expected Output: true

Q46. Write a JavaScript program to shift all bits of a number to the left by n positions.  
Input: num = 3, n = 2  
Expected Output: 12

Q47. Write a JavaScript program to shift all bits of a number to the right by n positions.  
Input: num = 16, n = 2  
Expected Output: 4

Q48. Write a JavaScript program to check if a number is divisible by 5 using bitwise operators.  
Input: num = 10  
Expected Output: true

Q49. Write a JavaScript program to check if a number is a multiple of 6 using bitwise operators.  
Input: num = 12  
Expected Output: true

Q50. Write a JavaScript program to find the Hamming distance between two numbers.  
Input: num1 = 5, num2 = 9  
Expected Output: 2

Social Share

Bikki Singh Instructor TechnoVlogs

Bikki Singh

Hi, I am the instructor of TechnoVlogs. I have a strong love for programming and enjoy teaching through practical examples. I made this site to help people improve their coding skills by solving real-world problems. With years of experience, my goal is to make learning programming easy and fun for everyone. Let's learn and grow together!