Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Visual C# And Databases

Authors: Philip Conrod, Lou Tylee

16th Edition

1951077083, 978-1951077082

Students also viewed these Databases questions

Question

Question What integration level should an employer choose?

Answered: 1 week ago