Bitwise AND of Numbers Range

Advanced

Welcome to the Bitwise AND Range Challenge! In this fun and educational challenge, you'll need to work with the binary versions of numbers and perform a bitwise AND operation on them. Let's see if you can find the common bits in a range of numbers!

The task is to implement a function range_bitwise_and that receives two integers, left and right, and returns the bitwise AND of all the numbers from left to right inclusive.

What is Bitwise AND?

The Bitwise AND operation compares each binary digit of two numbers. If both compared digits are 1, it produces 1; otherwise, it produces 0.

For example :

  • 5 in binary is 101
  • 6 in binary is 110
  • 5 & 6 in binary is 100 (which is 4 in decimal)

Explanation:

You have to consider the range inclusive and compute the bitwise AND for all numbers from left to right.

Example:

range_bitwise_and(5, 7) # returns 4 a# Explanation: Bitwise AND for numbers 5 (101), 6 (110), and 7 (111) results in 4 (100) range_bitwise_and(0, 1) # returns 0

Are you ready to take on the challenge? Let's go!

Note: The numbers involved in the function are non-negative integers.

Geek
Inputs

Arg 1:

5

Arg 2:

7
Expected Output
4
Actual Output
Bitwise AND of Numbers Range [advanced] | Coding for Kids