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”...
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
COMPUTER SYSTEMS&MOD MSGT/ET SA AC PKG
- Perform the following using DEV-C++ Show your solution Write a program that determines a student’s grade. It reads four test scores (between0 and 100) and calculates the grade based on the following rules: If the average score is 90 or more, the grade is ‘A’. If the average score is between 80 and 90, the grade is ‘B’. If the average score is between 70 and 80, the grade is ‘C’. If the average score is between 60 and 70, the grade is ‘D’. If the average score is less than 60, the grade is ‘F’.arrow_forwardWrite C expressions that evaluate to 1 when the following conditions are true, andto 0 when they are false. Assume x is of type int.A. Any bit of x equals 1. These are the rules... In several of the following problems, we will artificially restrict what programmingconstructs you can use to help you gain a better understanding of the bit-level,logic, and arithmetic operations of C. In answering these problems, your codemust follow these rules:. !!!!!!!Assumptions!!!!!!!Integers are represented in two’s-complement form.Right shifts of signed data are performed arithmetically.Data type int is w bits long. For some of the problems, you will be given aspecific value for w, but otherwise your code should work as long as w is amultiple of 8. You can use the expression sizeof(int)<<3 to compute w..!!!!!Forbidden!!!!!!! (==) or (!=)Conditionals (if or ?:), loops, switch statements, function calls, and macroinvocations.Division, modulus, and multiplication.Relative comparison operators…arrow_forwardWrite Algorithm and related theory of the following problem. Do not write code. C++: When a message is transmitted in secret code over a transmission channel, it is usually sent as a sequence of bits, that is, 0s and 1s. Due to noise in the transmission channel, the transmitted message may become corrupted. That is, the message received at the destination is not the same as the message transmitted; some of the bits may have been changed. There are several techniques to check the validity of the transmitted message at the destination. One technique is to transmit the same message twice. At the destination, both copies of the message are compared bit by bit. If the corresponding bits are the same, the message received is error-free. Response Required: Write a program to check whether the message received at the destination is error-free. For simplicity, assume that the secret code representing the message is a sequence of digits (0 to 9) and the maximum length of the message is 250…arrow_forward
- المزيد ... التقويم :what is the value of x according to the calculation .4 x = (4 + 2 * 3) + (16/4 + 1) (3 + 8)/4 * (2 نقطة) Apply rules of precedence and show your work أدخل إجابتك النشارarrow_forwardQ2/ (a) Write a program in C Language to read an integer number (X) to calculate and print Y values, using SWITHC FUČNTION based on the following equations: 3x -7 f x--3 y Sx f x= 2 or 5 x- 4x² if x = -4 or 4 (b) Find the solution of following set of liner equations in MATLAB. 2X-Y+Z=4 X+Y+Z=3 3X-Y-Z1arrow_forwardc++arrow_forward
- Matlabarrow_forward(For thought) Although you have concentrated on operations involving integer and floatingpoint numbers, C++ allows adding and subtracting characters and integers. (These operations are possible with characters because they’re integer data types and are stored by using integer codes.) Therefore, characters and integers can be mixed in arithmetic expressions. For example, if your computer uses the ASCII code, the expression 'a'+1equals'b'and'z'1equals'y'.Similarly,'A'+1is'B'and'Z'-1is'Y'. With this information as background, determine the character results of the following expressions. (Assume all characters are stored by using ASCII codes.) a.m5b.m+5c.G+6d.G6e.baf.ga+1g.GA+1arrow_forward(Numerical) Using the srand() and rand() C++ library functions, fill an array of 1000 floating-point numbers with random numbers that have been scaled to the range 1 to 100. Then determine and display the number of random numbers having values between 1 and 50 and the number having values greater than 50. What do you expect the output counts to be?arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning