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: A Programmer's Perspective (3rd Edition)
- Code the following.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_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_forwardplease explain the output of below codearrow_forwardPlease use C++ to solve the listed problems in one code 1). Decrypt the following: “DY CVOOZ ZOBMRKXMO DY NBOKW” 2). Convert 890 to base 9. 3). Determine if the bits of 1100010 is correct or not by using Hamming Code Detection method. If not, detect which bit is incorrect and print out the decimal format of the message that was sent after the correction 4). Universal Set: [A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T] Set A: [A, B, C, E, H, M] Set B: [A, C, E, G, I, K, M, O, Q, S] Set C: [A, B, C, E, G, K, M, Q, S] Please print out: ((A Union B) Intersect C) 5). Present a Truth Table for the following statement: !(A XOR B) NAND (A OR C) Please provide the code and a screenshot of outputarrow_forward
- Please answer in C++ Your country is at war and your enemies are using a secret code to communicate with one another. You have managed to intercept a message that reads as follows: :mmZ\dxZmx]Zpgy The message is obviously encrypted using the enemy's secret code. You have just learned that their encryption method is based upon the ASCII code. Appendix 3 shows the character set. Individual characters in string are encoded using this system. For example, the character "A" is encoded using the number 65, and "B" is encoded using the number 66. Your enemy's secret code takes each letter of the message and encrypts it as follows : if (orginalChar + key > 126) then encryptedChar = 32 + ((orginalChar + key) -127) else encryptedChar = (orginalChar +key) For example, if the enemy uses key = 10 then the message "Hey" would be encrypted as: Character ASCII code H 72 e 101 y…arrow_forwardUse C++ Complete main() to read dates from input, one date per line. Each date's format must be as follows: March 1, 1990. Any date not following that format is incorrect and should be ignored. Use the substr() function to parse the string and extract the date. The input ends with -1 on a line alone. Output each correct date as: 3/1/1990. Ex: If the input is: March 1, 1990 April 2 1995 7/15/20 December 13, 2003 -1 then the output is: 3/1/1990 12/13/2003arrow_forwardb) What is the difference between (x+H), (x+-), and (--x). c) Write the purpose for the use of the following: =, |I, //arrow_forward
- [Python (py3)] Displayed below is a code for matrix addition. However, there is an error that should be fixed in the code. The error in the code below is if the number of rows of the matrix is not equal to the number of columns of the same matrix, matrix addition will not be performed. This should not be the case so please fix this error. The only requirement for matrices addition is that the dimension of Matrix A is equal to the dimension of Matrix B, regardless if the number of rows of Matrix A and Matrix B is equal to the number of columns of Matrix A and Matrix B, respectively (see sample input and output below).Please resolve the error in the code below such that Matrix A and Matrix B can be added if the dimension of Matrix A is equal to the dimension of Matrix B. PLEASE do not just copy the code below and use it as the answer itself. I've encountered such case many times. Please modify the code. When the dimension of Matrix A is not equal to the dimension of Matrix B, print…arrow_forwardUse C++ A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to rotate around the sun. To account for the difference in time, every 4 years, a leap year takes place. A leap year is when a year has 366 days: An extra day, February 29th. The requirements for a given year to be a leap year are: 1) The year must be divisible by 4 2) If the year is a century year (1700, 1800, etc.), the year must be evenly divisible by 400 Some example leap years are 1600, 1712, and 2016. Write a program that takes in a year and determines whether that year is a leap year. Ex: If the input is: 1712 the output is: 1712 is a leap year. Ex: If the input is: 1913 the output is: 1913 is not a leap year. Your program must define and call the following function. The function should return true if the input year is a leap year and false otherwise.bool IsLeapYear(int userYear)arrow_forward6. Find the errors from the following code. a. T=[a,b,c] printlh (T) b. for i in 1 to 100 : print (1) c. i=10 while [ib) print (a): else if (aarrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
- 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