diff options
| -rw-r--r-- | 2/6.c | 17 | ||||
| -rw-r--r-- | 2/7.c | 15 | ||||
| -rw-r--r-- | 2/8.c | 11 | ||||
| -rw-r--r-- | 2/9.c | 4 |
4 files changed, 1 insertions, 46 deletions
@@ -1,21 +1,6 @@ #include <stdio.h> -unsigned setbits(unsigned x, int p, int n, unsigned y); - -int main(int argc, char *argv[]) { - int p, n; - unsigned x, y; - - p = 5; - n = 3; - x = 0; - y = 7; - - printf("New bit field: %x\n", setbits(x, p, n, y)); - - return 0; -} - +/* sets the n bits of x starting at p to rightmost n bits of y */ unsigned setbits(unsigned x, int p, int n, unsigned y) { unsigned yLO, yLOA, xUnset, xPrime; @@ -1,21 +1,6 @@ #include <stdio.h> /* inverts n bits of x starting at p */ -unsigned invert(unsigned x, int p, int n); - -int main(int argc, char * argv[]) { - int n, p; - unsigned x; - - n = 3; - p = 5; - x = 0xB7; - - printf("result: %x\n", invert(x, p, n)); - - return 0; -} - unsigned invert(unsigned x, int p, int n) { unsigned mask, y; @@ -1,17 +1,6 @@ #include <stdio.h> /* rotates x to the right by n positions */ -unsigned rightrot(unsigned x, int n); - -int main(int argc, char *argv[]) { - unsigned x; - - x = rightrot(0x7, 3); - printf("rotated: %x\n", x); - - return 0; -} - unsigned rightrot(unsigned x, int n) { return (x >> n) | (x << (32 - n)); }
\ No newline at end of file @@ -1,10 +1,6 @@ #include <stdio.h> /* counts 1-bits in x */ -int bitcount(unsigned x); - -int main(int argc, char *argv[]) { return 0; } - int bitcount(unsigned x) { // Explanation: on a two's complement system, x - 1 is performed by // adding the two's complement of 1 (i.e. 111...1) to x. Adding 1 to |
