Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
Bitwise AND of Numbers Range
Bookmark
Input
Example 1
Example 2
Example 3
Custom
left
=
5
,
right
=
7
7
6
5
4
3
2
1
0
left
= 5
& right
= 7
result
0
0
0
0
0
1
0
1
0
0
0
0
0
1
1
1
7
6
5
4
3
2
1
0
left
= 5
& right
= 7
result
0
0
0
0
0
1
0
1
0
0
0
0
0
1
1
1
7
6
5
4
3
2
1
0
left
= 5
& right
= 7
result
0
0
0
0
0
1
0
1
0
0
0
0
0
1
1
1
7
6
5
4
3
2
1
0
left
= 5
& right
= 7
result
0
0
0
0
0
1
0
1
0
0
0
0
0
1
1
1
7
>
5
: clear the lowest set bit of right
7
6
5
4
3
2
1
0
left
= 5
& right
= 6
result
0
0
0
0
0
1
0
1
0
0
0
0
0
1
1
0
right =
7
&
6
=
6
7
6
5
4
3
2
1
0
left
= 5
& right
= 6
result
0
0
0
0
0
1
0
1
0
0
0
0
0
1
1
0
6
>
5
: clear the lowest set bit of right
7
6
5
4
3
2
1
0
left
= 5
& right
= 4
result
0
0
0
0
0
1
0
1
0
0
0
0
0
1
0
0
right =
6
&
5
=
4
7
6
5
4
3
2
1
0
left
= 5
& right
= 4
result
0
0
0
0
0
1
0
1
0
0
0
0
0
1
0
0
4
<=
5
: stop
7
6
5
4
3
2
1
0
left
= 5
& right
= 4
result
= 4
0
0
0
0
0
1
0
1
0
0
0
0
0
1
0
0
0
0
0
0
0
1
0
0
result = left & right =
5
&
4
=
4
7
6
5
4
3
2
1
0
left
= 5
& right
= 4
result
= 4
0
0
0
0
0
1
0
1
0
0
0
0
0
1
0
0
0
0
0
0
0
1
0
0
AND of [5, 7] = 4
algo
master
.
io
Step:
AND every number from 5 to 7: the differing low bits get wiped out, only the shared prefix survives
0 / 8
Input
Example 1
Example 2
Example 3
Custom
left
=
5
,
right
=
7
0 / 8
algo
master
.
io
Step:
AND every number from 5 to 7: the differing low bits get wiped out, only the shared prefix survives