Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Use the following information. Assumptions Data type int is 32 bits long. Right shifts of signed data are performed arithmetically. Forbidden Casting, either explicit
Use the following information. Assumptions Data type int is 32 bits long. Right shifts of signed data are performed arithmetically. Forbidden Casting, either explicit or implicit. Relative comparison operators (, =). Division, modulus, and multiplication. Conditionals (if or ? :), loops, switch statements, function calls, and macro invocations. Equality (==) and inequality (!=) only for test cases Allowed operations Even with these rules, you should try to make your code readable by choosing descriptive variable names and using comments to describe the logic behind your solutions. All bit-level and logic operations Addition and Subtraction Background: Everytime an x86-64 processor executes an arithmetic or logical operation, it sets a 1-bit condition code flag, named PF (for "parity flag"), to 1 when lower 8 bits in the resulting computation have an odd number of ones and to 0 otherwise. Consider following table with examples: 8 bits of data 00000000 10100010 11010010 01111111 * * (count of 1-bits) This computation of PF for lower 8 bits is performed by hardware as part of every arithmetic or logical operation. For this problem, you are required to replicate the behavior of parity flag computation for all 32-bit int type data using C code agreeing with the rules listed above. Write code for the function with the following prototype. Place your code for hwk2a (And only the code for hwk2a in a file hwk2a.c You will need to submit the C file in a zip archive to the gradescope autograder. (30 points) /* * hwk2a - returns 1 if value contains an odd number of 1's Examples: hwk2a(5) = 0, hwk2a(7) = 1 Legal ops: ! & ^ | + < < >> 0 3 4 7 */ int hwk2a(int value){ return 2; PF 0 1 0 1
Step by Step Solution
★★★★★
3.51 Rating (144 Votes )
There are 3 Steps involved in it
Step: 1
Answer write a C function hwk2a that determines whether a 32bit integer has an odd number of set bit...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started