Write C expressions that evaluate to 1 when the following conditions are true, and to 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 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: . !!!!!!!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 a specific value for w, but otherwise your code should work as long as w is a multiple of 8. You can use the expression sizeof(int)<<3 to compute w. .!!!!!Forbidden!!!!!!! (==) or (!=) Conditionals (if or ?:), loops, switch statements, function calls, and macro invocations. Division, modulus, and multiplication. Relative comparison operators (<, >, <=, and >=). Casting, either explicit or implicit. . !!!!!!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. Integer constants INT_MIN and INT_MAX.
Write C expressions that evaluate to 1 when the following conditions are true, and
to 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 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:
. !!!!!!!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 a
specific value for w, but otherwise your code should work as long as w is a
multiple of 8. You can use the expression sizeof(int)<<3 to compute w.
.!!!!!Forbidden!!!!!!!
(==) or (!=)
Conditionals (if or ?:), loops, switch statements, function calls, and macro
invocations.
Division, modulus, and multiplication.
Relative comparison operators (<, >, <=, and >=).
Casting, either explicit or implicit.
. !!!!!!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.
Integer constants INT_MIN and INT_MAX.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps