![EBK COMPUTER SYSTEMS](https://www.bartleby.com/isbn_cover_images/8220101459107/8220101459107_largeCoverImage.jpg)
A.
Explanation of Solution
C expression for given statement:
The C expression for any bit of “x” equals “1” is shown below.
Expression: !~x
For the above expression “!~x”, a complete program has been developed in the below section:
//Header file
#include <stdio.h>
#include <assert.h>
//Function definition "A" statement
int partA(int x)
{
/* Returns "1" if any bits of "x" equals "1" by using expression "!~x" */
return !~x;
}
//Main function
int main(int argc, char* argv[])
{
//Assign all bit is "1"
int allBit1 = ~0;
//Assign all bit is "0"
int allBit0 = 0;
/* Call partA function with "alllBit1" using "assert" function */
assert(partA(allBit1));
/* Call partA function with "alllBit0" using "assert" function */
assert(!partA(allBit0));
/* Call partA function with number "0x1234FF" using "assert" function */
assert(!partA(0x1234FF));
return 0;
}
From the given code,
- Define the function for “partA()”
- In this function, returns “1” if any bits of “x” equals “1” by using the expression “!~x”...
B.
Explanation of Solution
C expression for given statement:
The C expression for any bit of “x” equals “0” is shown below.
Expression: !x
Program:
For the above expression “!x”, a complete program has been developed in the below section:
//Header file
#include <stdio.h>
#include <assert.h>
//Function definition "B" statement
int partB(int x)
{
/* Returns "1" if any bits of "x" equals "0" by using expression "!x" */
return !x;
}
//Main function
int main(int argc, char* argv[])
{
//Assign all bit is "1"
int allBit1 = ~0;
//Assign all bit is "0"
int allBit0 = 0;
/* Call partB function with "alllBit1" using "assert" function */
assert(!partB(allBit1));
/* Call partB function with "alllBit0" using "assert" function */
assert(partB(allBit0));
/* Call partB function with number "0x1234FF" using "assert" function */
assert(!partB(0x1234FF));
return 0;
}
From the given code,
- Define the function for “partB()”
- In this function, returns “1” if any bits of “x” equals “0” by using the expression “!x”.
- Define the main function
- In this function, assign “~0” in variable “allBit1”...
C.
Explanation of Solution
C expression for given statement:
The C expression for any bit in the least significant byte of “x” equals “1” is shown below.
Expression: !~(x | ~0xff)
Program:
For the above expression “!~(x | ~0xff)”, a complete program has been developed in the below section:
//Header file
#include <stdio.h>
#include <assert.h>
//Function definition "A" statement
int partA(int x)
{
/* Returns "1" if any bits of "x" equals "1" by using expression "!~x" */
return !~x;
}
//Function definition "C" statement
int partC(int x)
{
/* Returns "1" if any bits in the least significant byte of "x" equals "1" by calling the function "partA" with "x | ~0xff" */
return partA(x | ~0xff);
}
//Main function
int main(int argc, char* argv[])
{
//Assign all bit is "1"
int allBit1 = ~0;
//Assign all bit is "0"
int allBit0 = 0;
/* Call partC function with "alllBit1" using "assert" function */
assert(partC(allBit1));
/* Call partC function with "alllBit0" using "assert" function */
assert(!partC(allBit0));
/* Call partC function with number "0x1234FF" using "assert" function */
assert(partC(0x1234ff));
return 0;
}
From the given code,
- Define the function for “partA()”
- In this function, returns “1” if any bits of “x” equals “1” by using the expression “!~x”...
D.
Explanation of Solution
C expression for given statement:
The C expression for any bit in the least significant byte of “x” equals “0” is shown below.
Expression: !((x >> ((sizeof(int)-1) << 3)) & 0xff)
Program:
For the above expression “!((x >> ((sizeof(int)-1) << 3)) & 0xff)”, a complete program has been developed in the below section:
//Header file
#include <stdio.h>
#include <assert.h>
//Function definition "B" statement
int partB(int x)
{
/* Returns "1" if any bits of "x" equals "0" by using expression "!x" */
return !x;
}
//Function definition "D" statement
int partD(int x)
{
/* Returns "1" if any bits in the least significant byte of "x" equals "0" by calling the function "partB" with "x >> ((sizeof(int)-1) << 3)) & 0xff" */
return partB((x >> ((sizeof(int)-1) << 3)) & 0xff);
}
//Main function
int main(int argc, char* argv[])
{
//Assign all bit is "1"
int allBit1 = ~0;
//Assign all bit is "0"
int allBit0 = 0;
/* Call partB function with "alllBit1" using "assert" function */
assert(!partD(allBit1));
/* Call partB function with "alllBit0" using "assert" function */
assert(partD(allBit0));
/* Call partB function with number "0x1234FF" using "assert" function */
assert(partD(0x1234ff));
return 0;
}
From the given code,
- Define the function for “partB()”
- In this function, returns “1” if any bits of “x” equals “0” by using the expression “!x”...
![Check Mark](/static/check-mark.png)
Want to see the full answer?
Check out a sample textbook solution![Blurred answer](/static/blurred-answer.jpg)
Chapter 2 Solutions
EBK COMPUTER SYSTEMS
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY
![Text book image](https://www.bartleby.com/isbn_cover_images/9780133594140/9780133594140_smallCoverImage.gif)
![Text book image](https://www.bartleby.com/isbn_cover_images/9780124077263/9780124077263_smallCoverImage.gif)
![Text book image](https://www.bartleby.com/isbn_cover_images/9781337569330/9781337569330_smallCoverImage.gif)
![Text book image](https://www.bartleby.com/isbn_cover_images/9781337093422/9781337093422_smallCoverImage.gif)
![Text book image](https://www.bartleby.com/isbn_cover_images/9780133750423/9780133750423_smallCoverImage.jpg)
![Text book image](https://www.bartleby.com/isbn_cover_images/9781119368830/9781119368830_smallCoverImage.gif)