If x is an unsigned type, or signed with a non-negative value, yes.
The % operator yields 'what remains' from division; the & operator
yields
'what remains' if you exclude certain value bits.
But they don't both do that. % is defined (in C99) as an essentially
arithmetic operation,
No less in C90.
while & is defined in terms of the representation.
Yes and no. It operates on value and sign bits, but not padding bits.
One can think of x % 1000 as a decimal-wise masking of value places,
so
there is a relation between &1, &3, &7, ... and %10, %100, %1000...
This is most clearly seen when A is negative.
In the general case, C programmers shouldn't be using bitwise
operators
on signed types. If we limited the discussion to unsigned types, then
in that (ideal) environment, your point is of no consequence.
Under C90, division needn't round towards zero, so even for %, there
is a case to limit use to non-negative integers for consistent
results.
Of course, the real question is when to use &7 and when to use %8.
The answer to that depends on context. If you want the remainder when
dividing by 8, then use %. If you want the lower 3 bits, then use &.
Whilst division can be expensive on some CPUs, most modern compilers
are more than good enough to optimise %8 without programmer
assistance.
If you see &7 used in place of %8, then you're just witnessing someone
using something that was clever and critcal 40+ years ago, not
something
that's clever or critical now. Or, if there's a case where the
compiler
isn't optimising %8 to &7, then it's more likely the code isn't using
the most practical type for the operation at hand (e.g. using int
rather
than size_t.)