diff options
| author | Sadeep Madurange <smadurange@users.noreply.github.com> | 2021-11-29 22:14:15 +0800 |
|---|---|---|
| committer | Sadeep Madurange <smadurange@users.noreply.github.com> | 2021-11-29 22:14:15 +0800 |
| commit | 3147770dcec9f76d7137a5e05389ccdeed9a86df (patch) | |
| tree | f819f727fba6718c49baa45e2eb68a1125e501ab /2/6.c | |
| parent | e18135c4f76c84063ba17b5a0eb03511c2e575e4 (diff) | |
| download | k&r-exercises-3147770dcec9f76d7137a5e05389ccdeed9a86df.tar.gz | |
2.6
Diffstat (limited to '2/6.c')
| -rw-r--r-- | 2/6.c | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -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; |
