From c800a6727d58641f97db0f24a6e3ad1076a4eec7 Mon Sep 17 00:00:00 2001 From: Sadeep Madurange Date: Wed, 1 Dec 2021 21:44:14 +0800 Subject: Clean up. --- 2/6.c | 17 +---------------- 2/7.c | 15 --------------- 2/8.c | 11 ----------- 2/9.c | 4 ---- 4 files changed, 1 insertion(+), 46 deletions(-) diff --git a/2/6.c b/2/6.c index bf8cf2f..bb8c1de 100644 --- a/2/6.c +++ b/2/6.c @@ -1,21 +1,6 @@ #include -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; diff --git a/2/7.c b/2/7.c index 0c2ae6f..97af143 100644 --- a/2/7.c +++ b/2/7.c @@ -1,21 +1,6 @@ #include /* 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; diff --git a/2/8.c b/2/8.c index 2d57301..4ce829b 100644 --- a/2/8.c +++ b/2/8.c @@ -1,17 +1,6 @@ #include /* 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 diff --git a/2/9.c b/2/9.c index 06a675a..7df5637 100644 --- a/2/9.c +++ b/2/9.c @@ -1,10 +1,6 @@ #include /* 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 -- cgit v1.2.3