Are bitwise operators in C used both for bit operations and for operations for integer or some C types?


I’ve actually upvoted this question, as a perfectly legitimate question from someone attempting to learn.

The first thing to say is that it’s conventional to distinguish between either “bitwise operators”, or “logical operators”. A “bitwise logical operator” sounds like a conflation according to this conventional distinction, even though it’s possible to make sense of the term as you are using it (since a bitwise operator typically applies a logical operator to an array of bits).

The “bitwise logical operators” and the “bitwise shift operators” are rarely if ever distinguished – both simply falling under the heading of “bitwise operators”.

A “logical operator”, conventionally, means an operator that folds multi-bit operands down to a single bit, and produces a result which is a single bit. Hence, you have the distinction between “bitwise NOT” (a straightforward inversion of all bits) and “logical NOT” (folding all bits with an OR operation to yield a single bit, followed by an inversion of that single bit – or something similar depending on the exact implementation and architectural details).

So your question concerns what are normally referred to simply as “bitwise operators”.

To answer the first of your questions, bitwise shifting is certainly used on integers. For example, multiplying an integer by 2, is generally equivalent to a bitwise left-shift of the same integer.

Your second question is a little ambiguous, but if it means “are bitwise shift operators used to select or manipulate individual bits”, then yes, they can be.