A.
Explanation of Solution
C expression for “
The C expression for “
Expression: -1 << k
For the above expression “-1 << k”, a complete program has been developed in the below section:
//Header file
#include <stdio.h>
#include <assert.h>
//Function definition for part A
int partA(int k)
{
//Returns the value of given expression
return -1 << k;
}
//Main function
int main(int argc, char* argv[])
B.
Explanation of Solution
C expression for “
The C expression for “
Expression: ~(-1 << k) << j
Program:
For the above expression “~(-1 << k) << j”, a complete program has been developed in the below section:
//Header file
#include <stdio.h>
#include <assert.h>
//Function definition for part A
int partA(int k)
{
//Returns the value of given expression
return -1 << k;
}
//Function definition for part B
int partB(int k, int j)
{
/* Returns the value of given expression by calling function "partA" */
return ~partA(k) << j;
}
//Main function
int main(int argc, char* argv[])
{
/* Call function "partB" with checking value using "assert" function */
assert(partB(24, 8) == 0xFFFFFF00);
return 0;
}
The given code is used to return the value of expression “~(-1 << k) << j”
Trending nowThis is a popular solution!
Chapter 2 Solutions
Computer Systems: Program... -Access
- Write a C-function with two arguments (n and r) that has prototype: char clearbit(char k, char bits) The function clears (sets to 0) the bit number k (in the range of 0 to 7) in bits and returns the resulting value. For example, if k is 0x02 and bits is 0x07, the function would return bits with its k’th bit cleared, resulting in 0x03. It must not change other bits in bits. Hint: You may use any number of C-statements, but this task can be accomplished in as few as one!arrow_forward1. Write a C++ program that takes two binary numbers of 8 bits eachrepresented with the letters Z and O (for zero or one) and displays thesum in binary with Zs and Os. Do this by converting the numbers to ints,adding the its using +, displaying the 3 ints, then converting the sum toZ and Os and displaying the result. 1 a.) Redo number 1, by doing a bit-by-bit addition, not forgetting the carry. 1b.) Write a program to take two numbers represented with romannumerals and display the sum. Assume the sum will be less than 20.Hints: Ask the user to terminate each number with a semicolon and usechars to hold the roman ‘digits’.The numbers are I, II, III IV, V, VI, VII, VIII, IX, X, XI, XII, XIII, XIV, XV…isfive, Change the program to allow the sum to go up to 49 See how large a number you can handle. L is 50, C is 100, M is 1000. Using basic C++ int, char, if- else statements, and switch statements, please! no functions, or strings, or Cmath etc.arrow_forwardIn c++ Now write a program for a double floating pointtype.•What are the number of significant bits that the double’s mantissa can hold, excluding the sign bit.•What is the largest number that a double’s mantissa can hold without roundoff error?•Repeat the program shown on the previous page but set to show where the double’s mantissa starts to exhibit roundoff errors.arrow_forward
- I want to write C or C++ functions that evaluate to ONE when the given conditions are true, and to ZERO when they are false. The following are the fourt conditions: int a(int x); //Any bit of x equals 0. int b(int x); // Any bit of x equals 1. int c(int x); //Any bit in the LSB of x equals 0. int d(int x); //Any bit in the MSB of x equals 1. The code should follow the bit-level integer coding rules, with the additional restriction that you may not use equality (==) or inequality (!=) tests.arrow_forwardImplement the following error detection and error correction algorithms using C programming for Hamming code. For Hamming codes, flip a bit in the data and implement the algorithm to correct the same on the receiver side.arrow_forwardUse a Windows programme that applies these operators to a pair of values to illustrate how the bitwise operators in C# operate. To interact with the bitwise operators, we'll make use of the ConvertBits function that was previously built.arrow_forward
- Please use C++ In this lab, you need to write a program which, given a seven digit binary input given below, it will check to see if there is a single bit error using the Hamming Code method discussed in lab. For a sample of Hamming Code, the input: 1110101 will reveal that ‘110’ is the location of the error (meaning the sixth slot in the input), so the corrected number would be 1010101, and the actual message transmitted, would be 1011, which is 11 in decimal. You can use this example to test your program to ensure it’s working correctly. Create a program which can, given a 7-bit long input, written in Hamming Code style, do the three following tasks, displaying the results as output. (1) Determine if there’s an incorrect bit, and if so, where it is. (2) Display what the CORRECT code should look like (if it needs to be corrected.) (3) Display the decimal form of the message that was sent, after any needed correction. Remember, when using Hamming…arrow_forwardSuppose we number the bytes in a w-bit word from 0 (least significant) to w/8 – 1 (most significant). Write code for the following C function, which will return an unsigned value in which byte i of argument x has been replaced by byte b: unsigned replace_byte (unsigned x, int i, unsigned char b); Here are some examples showing how the function should work: replace_byte(0x12345678, 2, 0xAB) --> 0x12AB5678 replace_byte(0x12345678, 0, 0xAB) --> 0x123456AB Bit-Level Integer Coding Rules In several of the following problems, we will artificially restrict what programming constructs 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 code must follow these rules: Allowed operations All bit-level and logic operations. Left and right shifts, but only with shift amounts between 0 and w – 1. Addition and subtraction. Equality (==) and inequality (!=) tests. (Some of the problems do not allow…arrow_forwardIn C, write a function int setbit(int n, int i) to set the i^ᵗʰ bit of n if i^ᵗʰ bit is 0.arrow_forward
- Please write in C program to print out a list of bit strings that can be created by using combination How many bit strings of length 12 containa) exactly three 1s?b) at most three 1s?c) at least three 1s?d) an equal number of 0s and 1s?arrow_forward3. Write a C++ program to find the count of set bits in the number 1000 and display the number of set bits in the output.arrow_forwardIn the Hamming coding system (7.3), its representation is expressed as 3 control (test) bits and 7 total bits (data+control bits).In the literature, control bits are represented as (cl, c2, c3, or (pl, p2, p3, .) The bit string sent by encoding with Hamming coding (15,4) is on the receiving side, It is retrieved as 001100101100 (pl.p2.dll). According to this bit sequence;Which option is given according to the control bits (p1.p2.p3.p4) sequence of the received bit sequence?A 0110B 1100C 1001D 0011E 0010arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education