In C complete each of the functions using only straightline code no loops or conditionals and only using the legal operators listed for each function.
In C complete each of the functions using only straightline code no loops or conditionals and only using the legal operators listed for each function.
/*
* bitNand - ~(x&y) using only ~ and |
* Example: bitNand(0x6, 0x5) = 0xFFFFFFFB
* Legal ops: ~ |
* Max ops: 8
* Rating: 10
*/
int bitNand(int x, int y) {
return 2;
}
/*
* middleBits - return word with bits 15 and 16 set to 1.
* Legal ops: ! ~ & ^ | + << >>
* Max ops: 8
* Rating: 10
*/
int middleBits(void) {
return 2;
}
/*
* getByte - Extract byte n from word x
* Bytes numbered from 0 (LSB) to 3 (MSB)
* Examples: getByte(0x12345678,1) = 0x56
* Legal ops: ! ~ & ^ | + << >>
* Max ops: 6
* Rating: 8
*/
int getByte(int x, int n) {
return 2;
}
/*
* allOddBits - return 1 if all odd-numbered bits in word set to 1
* Examples allOddBits(0xFFFFFFFD) = 0, allOddBits(0xAAAAAAAA) = 1
* Legal ops: ! ~ & ^ | + << >>
* Max ops: 12
* Rating: 6
*/
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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