CODE
// Write a function that returns 0 if x is 0, returns -1
// if x < 0, returns 1 if x > 0
// Your code must follow the Bit-Level Integer Coding Rules
// on the textbook (located between hw 2.60 and 2.61).
// You can assume w = 32.
// The only allowed operations in your code are:
// ! ~ & ^ | + << >>
// This requirement is more restrictive than the coding rules.
int sign(int x) {
return 1 + (x >> 31) - (-x >> 31);
}
Get Answers For Free
Most questions answered within 1 hours.