Credits: Computer Systems: A Programmer's Perspective
Authors: Randal E. Bryant and David R. O'Hallaron
Samples of book: http://csapp.cs.cmu.edu/public/manuscript.html
Disclaimer: I have written permission from the author to post his labs on my site.
In this challenge your goal is to edit a series of functions in bits.c to mimic the behavior of bit Ands, Nors, etc... with restrictions to what operators
you can use.
One of the functions in the bits.c code is:
/* * bitAnd - x&y using only ~ and | * Example: bitAnd(6, 5) = 4 * Legal ops: ~ | * Max ops: 8 * Rating: 1 */ int bitAnd(int x, int y) { return 2; }
/* * bitAnd - x&y using only ~ and | * Example: bitAnd(6, 5) = 4 * Legal ops: ~ | * Max ops: 8 * Rating: 1 */ int bitAnd(int x, int y) { return ~(~x|~y); }
linux > make clean; make btest linux > ./btest -f bitAnd Test bitAnd score: 1.00/1.00 Overall correctness score: 1.00/1.00 All tests passed.