Solution: Make a Mask of Specified Width

The solution to the making a mask coding challenge is provided in this lesson.

We'll cover the following

Solution

The following method starts with a value when all of the bits are 1. First, the value is shifted to the right so that the upper bits become 0. Then, it is shifted to the left so that the lower bits become 0:

Get hands-on with 1200+ tech skills courses.