🌐
GeeksforGeeks
geeksforgeeks.org › c language › bitwise-operators-in-c-cpp
Bitwise Operators in C - GeeksforGeeks
In C, bitwise operators are used to perform operations directly on the binary representations of numbers.
Published   December 13, 2025
bitwise operations provided by the C programming language
In the C programming language, operations can be performed on a bit level using bitwise operators. Bitwise operations are contrasted by byte-level operations which characterize the bitwise operators' logical counterparts, the AND, … Wikipedia
🌐
Wikipedia
en.wikipedia.org › wiki › Bitwise_operations_in_C
Bitwise operations in C - Wikipedia
October 19, 2025 - In the C programming language, operations can be performed on a bit level using bitwise operators. Bitwise operations are contrasted by byte-level operations which characterize the bitwise operators' logical counterparts, the AND, OR, NOT operators. Instead of performing on individual bits, ...
Discussions

How do bitwise operators work in C?
N = 5 = (101)2 Actually, with 32-bit ints: N = 5 = 00000000000000000000000000000101 So ~N = ~5 = 11111111111111111111111111111010 And when those bits are in a signed int, you have the value -6 More on reddit.com
🌐 r/learnprogramming
8
1
February 18, 2022
bit manipulation - Bitwise Reduction Operators in C - Stack Overflow
Are there unary bitwise reduction operators in C like there are in Verilog? Like in Verilog we have: $display (" & 4'b1001 = %b", (& 4'b1001)); and the output of the function a... More on stackoverflow.com
🌐 stackoverflow.com
bit manipulation - Bitwise operation |= in C - Stack Overflow
I am going through example code and found this operation: displayMap[x + (y/8)*LCD_WIDTH]|= 1 (shift by) shift; where byte shift = y % 8; I understand | operand and = but what are two of them More on stackoverflow.com
🌐 stackoverflow.com
udp - C Programming - Bitwise operators and knowing when to utilize - Stack Overflow
You use bitwise operators when you want to view a number as a collection of bits, rather than an integer. It's much easier to say "I want this bit-pattern shifted two bits to the left" than to create the mathematically equivalent operation. More on stackoverflow.com
🌐 stackoverflow.com
🌐
W3Schools
w3schools.com › c › c_bitwise_operators.php
C Bitwise Operators
In C, bitwise operators let you work directly with the bits (the 1s and 0s) that make up numbers in binary form.
🌐
TutorialsPoint
tutorialspoint.com › home › cprogramming › c bitwise operators
C Bitwise Operators
June 10, 2012 - Additionally, the symbols ^ (XOR), << (left shift) and >> (right shift) are the other bitwise operators. Even though these operators work on individual bits, they need the operands in the form C data types or variables only, as a variable occupies ...
🌐
Programiz
programiz.com › c-programming › bitwise-operators
Bitwise Operators in C Programming
In the arithmetic-logic unit (which is within the CPU), mathematical operations like: addition, subtraction, multiplication and division are done in bit-level. To perform bit-level operations in C programming, bitwise operators are used.
🌐
Reddit
reddit.com › r/learnprogramming › how do bitwise operators work in c?
r/learnprogramming on Reddit: How do bitwise operators work in C?
February 18, 2022 -

Hey all! I got another beginner question. So, I'm learning about bitwise operators from this site. Here's what it says about the bitwise not:

Bitwise NOT is an unary operator that flips the bits of the number i.e., if the ith bit is 0, it will change it to 1 and vice versa. Bitwise NOT is nothing but simply the one’s complement of a number. Lets take an example.
N = 5 = (101)2
~N = ~5 = ~(101)2 = (010)2 = 2

So, ~5 = 2. Now, when I try this in C:

#include <stdio.h>

int main(void) {

int c = 5;

c = ~c;

printf("%d", c);

return 0;

}

The output of the above program is -6. What am I doing wrong?

🌐
Microsoft Learn
learn.microsoft.com › en-us › cpp › c-language › c-bitwise-operators
C Bitwise Operators | Microsoft Learn
April 7, 2022 - Access to this page requires authorization. You can try changing directories. ... The bitwise operators perform bitwise-AND (&), bitwise-exclusive-OR (^), and bitwise-inclusive-OR (|) operations.
Find elsewhere
🌐
Quora
quora.com › When-should-you-use-the-bitwise-operators-in-C
When should you use the bitwise operators in C? - Quora
Answer (1 of 2): When you need to perform operations on individual bits, of course. The results of the bitwise operators are not typically the same as the arithmetic equivalent. If you need to change the value of a single bit (fairly common when doing low-level programming of hardware registers, ...
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › csharp › language-reference › operators › bitwise-and-shift-operators
Bitwise and shift operators - perform boolean (AND, NOT, OR, XOR) and shift operations on individual bits in integral types - C# reference | Microsoft Learn
January 24, 2026 - For operands of the same enumeration type, a logical operation is performed on the corresponding values of the underlying integral type. For example, for any x and y of an enumeration type T with an underlying type U, the x & y expression produces the same result as the (T)((U)x & (U)y) expression. You typically use bitwise logical operators with an enumeration type that is defined with the Flags attribute.
🌐
GNU
gnu.org › software › c-intro-and-ref › manual › html_node › Bitwise-Operations.html
Bitwise Operations (GNU C Language Manual)
It is useful to remember that ~x + 1 equals -x, for integers, and ~x equals -x - 1. The last example above shows this with -1 as x. ... Binary operator for bitwise “and” or “conjunction.” Each bit in the result is 1 if that bit is 1 in both a and b.
🌐
Reddit
reddit.com › r/c_programming › where to learn about bitwise operators and such?
r/C_Programming on Reddit: Where to learn about bitwise operators and such?
November 22, 2022 -

Super beginner question, I apologize but I often see other people's see code and I see a lot of, 0xFE, ox00001, or >~ and I just don't understand what these are and why we need them. I google for bitwise operators and so far what I understand is that they operate on each bit of a byte and i guess & ands a 0/1, | ors >> shifts right and such. but why do we need these in actual coding environments where using these things is better than using normal variables.

also what are 0xFE called and where can I learn about them?

Top answer
1 of 12
40
0xFE is hexadecimal. The digits are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F. There are exactly 16 digits (hence "hexadecimal"). If you think about binary, if you have 4 binary digits, these can represent exactly 16 values. So, each hexadecimal digit maps nicely to 4 bits. 2 hexadecimal digits maps to exactly one byte. If you memorize the bit patterns for the 16 hex digits, then hexadecimal is a convenient way to type/read binary data. 0xFE is, in binary, 11111110 and since I'm familiar with hexadecimal, I didn't really have to think about it to know that. As for why you need to manipulate bits, there are a few reasons. One, some hardware register might define certain bits to do certain things, and you need to construct values to put in registers to make the right things happen on the hardware. Or, maybe a bunch of bits is a very compact way to represent a set of integers (1 = present, 0 = absent) or to represent, e.g. free or occupied array elements if you're writing your own fixed size allocator. There are undoubtedly many other reasons clever people can think of to use bitwise operations. Edit: an obvious one is e.g. the "flags" argument to open(2), which packs a bunch of boolean flags into a single integer parameter. As for where to learn about them, hexadecimal is easy enough, first column is binary, 2nd is corresponding hex digit: 0000 0x0 0001 0x1 0010 0x2 0011 0x3 0100 0x4 0101 0x5 0110 0x6 0111 0x7 1000 0x8 1001 0x9 1010 0xA 1011 0xB 1100 0xC 1101 0xD 1110 0xE 1111 0xF As for bitwise operations, there's a book called "Hacker's Delight" which has all manner of bit twiddling tricks in it.
2 of 12
26
The OG guide for bit twiddling and why to use it: https://graphics.stanford.edu/~seander/bithacks.html
🌐
Hero Vired
herovired.com › home › learning-hub › blogs › bitwise-operators-in-c
Bitwise Operators in C - Examples and Applications | Hero Vired
April 18, 2024 - Bitwise operators in C are special operators that perform operations at the binary level, working with individual bits of data rather than the entire data. These operators can manipulate the individual bits of integral data types, such as integers ...
🌐
GeeksforGeeks
geeksforgeeks.org › c language › operators-in-c
Operators in C - GeeksforGeeks
... #include <stdio.h> int main() ... printf("!a: %d\n", !a); return 0; } ... The Bitwise operators are used to perform bit-level operations on the operands....
Published   November 1, 2025
🌐
Microchip Developer Help
developerhelp.microchip.com › xwiki › bin › view › software-tools › compilers › c-programming › operators › bitwise
C Programming Bitwise Operators - Developer Help
Each of these operators performs their operations on each bit of the operands. For instance, if we have two 4-bit binary values, the operation will be carried out between bit 0 of each value, then between bit 1 of each value and so on. In other words, these operators do a bunch of single-bit ...
🌐
GameDev.net
gamedev.net › tutorials › programming › general-and-gameplay-programming › bitwise-operations-in-c-r1563
Bitwise Operations in C - General and Gameplay Programming - Tutorials - GameDev.net
October 30, 2001 - Simply convert each hex digit to its binary equivalent, and you're all done: 3FC = 0011 1111 1100 = 1111111100 Note that we can drop the leading zeroes, because they don't affect the value of the number, just as the decimal numbers 345 and 000345 are the same thing. All right, now you're all caught up on binary and hexadecimal, and you know why they're used. Let's get into the focus of this article, bitwise operations.
Top answer
1 of 4
172

Numbers can be expressed in binary like this:

3    = 000011
5    = 000101
10   = 001010

...etc. I'm going to assume you're familiar with binary.

Bitwise AND means to take two numbers, line them up on top of each other, and create a new number that has a 1 where both numbers have a 1 (everything else is 0).

For example:

    3          =>  00011
  & 5          =>  00101
------           -------
    1              00001

Bitwise OR means to take two numbers, line them up on top of each other, and create a new number that has a 1 where either number has a 1 (everything else is 0).

For example:

    3          =>  00011
  | 5          =>  00101
------           -------
    7              00111

Bitwise XOR (exclusive OR) means to take two numbers, line them up on top of each other, and create a new number that has a 1 where either number has a 1 AND the other number has a 0 (everything else is 0).

For example:

    3          =>  00011
  ^ 5          =>  00101
------           -------
    6              00110  

Bitwise NOR (Not OR) means to take the Bitwise OR of two numbers, and then reverse everything (where there was a 0, there's now a 1, where there was a 1, there's now a 0).

Bitwise NAND (Not AND) means to take the Bitwise AND of two numbers, and then reverse everything (where there was a 0, there's now a 1, where there was a 1, there's now a 0).

Continuing: why does word &= 15 set all but the 4 rightmost bits to 0? You should be able to figure it out now...

     n          =>  abcdefghjikl
  & 15          =>  000000001111
------            --------------
     ?              00000000jikl

(0 AND a = 0, 0 AND b = 0, ... j AND 1 = j, i AND 1 = i, ...)

How is this useful? In many languages, we use things called "bitmasks". A bitmask is essentially a number that represents a whole bunch of smaller numbers combined together. We can combine numbers together using OR, and pull them apart using AND. For example:

int MagicMap = 1;
int MagicWand = 2;
int MagicHat = 4;

If I only have the map and the hat, I can express that as myInventoryBitmask = (MagicMap | MagicHat) and the result is my bitmask. If I don't have anything, then my bitmask is 0. If I want to see if I have my wand, then I can do:

int hasWand = (myInventoryBitmask & MagicWand);
if (hasWand > 0) {
  printf("I have a wand\n");
} else {
  printf("I don't have a wand\n");
}

Get it?

EDIT: more stuff

You'll also come across the "bitshift" operator: << and >>. This just means "shift everything left n bits" or "shift everything right n bits".

In other words:

1 << 3 = 0001 << 3 = 0001000 = 8

And:

8 >> 2 = 01000 >> 2 = 010 = 2

2 of 4
2

"Bit" is short for "binary digit". And yes, it's a 0 or 1. There are almost always 8 in a byte, and they're written kinda like decimal numbers are -- with the most significant digit on the left, and the least significant on the right.

In your example, w1 & 3 masks everything but the two least significant (rightmost) digits because 3, in binary, is 00000011. (2 + 1) The AND operation returns 0 if either bit being ANDed is 0, so everything but the last two bits are automatically 0.