Last active
September 16, 2020 21:39
-
-
Save drguildo/4273bef094e163b26163e6106967b929 to your computer and use it in GitHub Desktop.
Solution to Practice Problem 2.13 in Computer Systems: A Programmer's Perspective.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void dump(unsigned int i) { | |
printf("%#08x = %d\n", i, i); | |
} | |
/* Declarations of functions implementing operations bis and bic */ | |
int bis(int x, int m) { | |
return x | m; | |
} | |
int bic(int x, int m) { | |
return x & ~m; | |
} | |
/* Compute x|y using only calls to functions bis and bic */ | |
int bool_or(int x, int y) { | |
int result = bis(x, y); | |
return result; | |
} | |
/* Compute x^y using only calls to functions bis and bic */ | |
int bool_xor(int x, int y) { | |
int result = bis(bic(x, y), bic(y, x)); | |
return result; | |
} | |
int main() { | |
dump(bool_or(0xFF, 0xFF00)); | |
dump(bool_or(0xFF, 0xFF)); | |
dump(bool_or(0xFE, 0xFF)); | |
dump(bool_xor(0xFF, 0xFF00)); | |
dump(bool_xor(0xFF, 0xFF)); | |
dump(bool_xor(0xFF, 0x01)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment