Challenge: Make a Mask of Specified Width

Here is a final coding challenge based on the concepts covered in this chapter.

Problem statement

Write a function that can be used for making a mask. It should start with the specified bit and have the specified width.

Sample input

mask(2, 5)

Sample output

124

Challenge

This problem is designed for you to practice, so try to solve it on your own first. If you get stuck, you can always refer to the explanation and solution provided in the next lesson. Good luck!

Get hands-on with 1000+ tech skills courses.