Bitwise AND of Numbers in the Range

Published by Evgeny SH in

The function is given two numbers begin, end that define a range of numbers, inclusive. Starting from begin apply bitwise & to the next one until the end to compute the outcome and return it.

Examples

bitwise_and(0, 1) ➞ 0
# input  = 0:0b0 & 1:0b1
# output = 0:0b0

bitwise_and(1, 1) ➞ 1
# input  = 1:0b1
# output = 1:0b1

bitwise_and(5, 7) ➞ 4
# input  = 5:0b101 & 6:0b110 & 7:0b111
# output = 4:0b100

bitwise_and(19, 22) ➞ 16
# input  = 19:0b10011 & 20:0b10100 & 21:0b10101 & 22:0b10110
# output = 16:0b10000

Notes

N/A

Watch a quick demo on how Edabit works.