Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Change meaning of p argument
Previusly: counted from the right of n

	xxx..xnnnnx..xxx
		 p     0

Now: counted from the left of n (like the book)

	xxx..xnnnnx..xxx
	      p        0
  • Loading branch information
isidroas committed Feb 16, 2025
commit 4f4d6bba86aa386ff93004f387e94a79446cff0f
4 changes: 2 additions & 2 deletions chapter-2-types-operators-expressions/11.setbits.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ main()

int setbits(int x, int p, int n, int y)
{
x = x & (~((~(~0 << n)) << p));
y = (y & (~(~0 << n))) << p;
x = x & (~((~(~0 << n)) << (p - n + 1)));
y = (y & (~(~0 << n))) << (p - n + 1);

return x | y;
}
Expand Down