summaryrefslogtreecommitdiffstats
path: root/2
diff options
context:
space:
mode:
Diffstat (limited to '2')
-rw-r--r--2/6.c17
-rw-r--r--2/7.c15
-rw-r--r--2/8.c11
-rw-r--r--2/9.c4
4 files changed, 1 insertions, 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 <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;
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 <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;
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 <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
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 <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