summaryrefslogtreecommitdiffstats
path: root/2/6.c
diff options
context:
space:
mode:
authorSadeep Madurange <smadurange@users.noreply.github.com>2021-11-29 22:14:15 +0800
committerSadeep Madurange <smadurange@users.noreply.github.com>2021-11-29 22:14:15 +0800
commit3147770dcec9f76d7137a5e05389ccdeed9a86df (patch)
treef819f727fba6718c49baa45e2eb68a1125e501ab /2/6.c
parente18135c4f76c84063ba17b5a0eb03511c2e575e4 (diff)
downloadk&r-exercises-3147770dcec9f76d7137a5e05389ccdeed9a86df.tar.gz
2.6
Diffstat (limited to '2/6.c')
-rw-r--r--2/6.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/2/6.c b/2/6.c
index 67d7c09..a8f2120 100644
--- a/2/6.c
+++ b/2/6.c
@@ -19,16 +19,16 @@ int main(int argc, char *argv[]) {
unsigned setbits(unsigned x, int p, int n, unsigned y) {
unsigned yLO, yLOA, xUnset, xPrime;
- // extract LO n bits from y
+ // extract n LO bits from y
yLO = y & ~(~0 << n);
- // align extracted LO bits of y to position p:
+ // align extracted bits to p:
yLOA = yLO << (p + 1 - n);
- // create mask with n bits from position p unset:
+ // mask with n bits from p unset:
xUnset = (~0 << p) | ~(~0 << (p - n));
- // mask out n bits from x starting at position p:
+ // mask out n bits in x from p:
xPrime = x & xUnset;
return xPrime | yLOA;