Question: Write a function called mask_LSbits( ). This function must have the following prototype: int mask_LSbits( int n ); This function creates (returns) a mask with

Write a function called mask_LSbits( ). This function must have the following prototype:

int mask_LSbits( int n );

This function creates (returns) a mask with the n least significant bits set (to 1). For example, if n is 2, the function returns 3 (i.e., 0x00000003) and if n is 15, the function returns 32767 (i.e., 0x00007fff).

What happens when n >= w or when **n <= 0**? When n >= w, your function must return a mask of all 1s. When n <= 0, your function must return a mask of all 0s, i.e., 0.

Requirements (for e.):

When creating the mask, while implementing this function, you must not use

division, modulus and/or multiplication,

iterative statements (such as loops),

call other function(s),

however, you can use sizeof().

Exceptions:

You can call the function sizeof() as many times as you wish. If you call sizeof() (note that you do not have to), you can then use multiplication with it. For example: sizeof() * 8.

You can use conditional statements in your function only when you validate the parameter.

Testing: For part e., make sure you test your code with test cases that use valid and invalid test data. Here is an example of a test case that uses valid test data: calling mask_LSbits(4) Here is an example of a test case that uses invalid test data: calling mask_LSbits(0)

language is C

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!