🌐
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   October 8, 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
language agnostic - Real world use cases of bitwise operators - Stack Overflow
I remember when I first learned ... c... but since then they've entered by toolbox and I use them often, including when doing "high-level" programming. They're just like + and * for me now. ... @Anon.: In my mind, real world was supposed to mean anything but low level programming which is the most obvious use of bitwise operators... More on stackoverflow.com
🌐 stackoverflow.com
objective c - Understanding the bitwise AND Operator - Stack Overflow
I have been reading about bit operators in Objective-C in Kochan's book, "Programming in Objective-C". I am VERY confused about this part, although I have really understood most everything else presented to me thus far. ... Bitwise ANDing is frequently used for masking operations. More on stackoverflow.com
🌐 stackoverflow.com
Struggling with Bitwise operators(K&R part 2.9)
The easiest way to understand this stuff is to write all of the examples out in binary and go through them step-by-step. Take this passage from K&R part 2.9: The unary ~ yields the one's complement of an integer; that is, it converts each 1-bit into a 0-bit and vice versa. For example, x = x & ~077 sets the last six bits of x to zero. There's a lot going on here. To understand it, let's start by writing 077 out in binary. Integer literals that start with a 0 are interpreted in octal (base 8) in C, which means each digit corresponds to 3 bits. 000 111 111 0 7 7 Written out this way, it's easy to see that 077 is an integer with the six lowest (i.e., rightmost) bits set to 1, and all the rest set to 0. Now, if we take the one's complement of that integer, using the ~ operator, we'll get an integer with the six lowest bits set to 0 and all the rest set to 1. The exact value of the result depends on how many bits are in an integer. I'll use 16 bits to make this example easier to write; modern computers typically use 32. ~ 0000 0000 0011 1111 (= 077) --------------------- 1111 1111 1100 0000 Finally, we take this new integer and bitwise-and it with some arbitrary integer x.* Since we don't know or care what the bits in x are, I'll just write them all as b, for "bit": bbbb bbbb bbbb bbbb & 1111 1111 1100 0000 --------------------- bbbb bbbb bb00 0000 The result, as we can now see quite easily, is in fact x with its lowest six bits set to zero! *If you don't understand bitwise and, here's a quick example. Suppose you have two binary numbers, 1100 and 0110. To compute 1100 & 0110, all you do is line them up next to each other... 1100 & 0110 ------ 0100 ...and then do a logical and on each pair of corresponding bits (i.e., each column), treating 1 as "true" and 0 as "false". Before moving on, you should convince yourself that and-ing any bit with 0 gives you a 0. and-ing any bit with 1 gives you back the original bit. More on reddit.com
🌐 r/C_Programming
9
13
December 27, 2016
People also ask

What is the difference between logical and bitwise operators in C?
Logical operators (&&, ||, !) evaluate conditions and return 1 or 0 based on truth values, while bitwise operators operate on individual bits of integers and return results based on bitwise comparisons.
🌐
wscubetech.com
wscubetech.com › resources › c-programming › bitwise-operators
Bitwise Operators in C Language (All Types With Examples)
Can bitwise operators cause overflow?
Yes, shifting bits out of an integer’s bounds or performing bitwise operations without proper masking can lead to overflow or unintended results.
🌐
wscubetech.com
wscubetech.com › resources › c-programming › bitwise-operators
Bitwise Operators in C Language (All Types With Examples)
Can bitwise operators in C be used with floating-point numbers?
No, bitwise operators are generally used with integers. Bitwise operations require binary representations without fractional parts.
🌐
wscubetech.com
wscubetech.com › resources › c-programming › bitwise-operators
Bitwise Operators in C Language (All Types With Examples)
🌐
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 › cprogramming › c_bitwise_operators.htm
Bitwise Operators in C
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 a specific number of bytes in the memory.
🌐
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.
🌐
ScholarHat
scholarhat.com › home
Bitwise Operators in C: AND, OR, XOR, Shift & Complement
Explore bitwise operators in C: learn their types, understand bitwise AND, OR, XOR, complement, and shift operations with practical examples.
Published   January 25, 2025
Find elsewhere
🌐
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?

🌐
Scaler
scaler.com › topics › c › bitwise-operators-in-c
Bitwise Operators in C - Scaler Topics
March 8, 2022 - Many people have a tendency to confuse them with the Bitwise AND, and Bitwise OR operators. So, let’s try to understand how are they different from each other. The logical operators work with Boolean data and return a Boolean value, i.e. True or False. The bitwise operators in C work with integers, i.e.
🌐
YouTube
youtube.com › bro code
C bitwise operators 🔣 - YouTube
C bitwise operators & | ^ tutorial example explained#C #bitwise #operators
Published   October 6, 2021
Views   73K
🌐
WsCube Tech
wscubetech.com › resources › c-programming › bitwise-operators
Bitwise Operators in C Language (All Types With Examples)
August 29, 2025 - A complete guide to bitwise operators in C language. Discover how to use AND, OR, XOR, NOT, and shift operators with practical examples and syntax.
Top answer
1 of 16
281
  • Bit fields (flags)
    They're the most efficient way of representing something whose state is defined by several "yes or no" properties. ACLs are a good example; if you have let's say 4 discrete permissions (read, write, execute, change policy), it's better to store this in 1 byte rather than waste 4. These can be mapped to enumeration types in many languages for added convenience.

  • Communication over ports/sockets
    Always involves checksums, parity, stop bits, flow control algorithms, and so on, which usually depend on the logic values of individual bytes as opposed to numeric values, since the medium may only be capable of transmitting one bit at a time.

  • Compression, Encryption
    Both of these are heavily dependent on bitwise algorithms. Look at the deflate algorithm for an example - everything is in bits, not bytes.

  • Finite State Machines
    I'm speaking primarily of the kind embedded in some piece of hardware, although they can be found in software too. These are combinatorial in nature - they might literally be getting "compiled" down to a bunch of logic gates, so they have to be expressed as AND, OR, NOT, etc.

  • Graphics There's hardly enough space here to get into every area where these operators are used in graphics programming. XOR (or ^) is particularly interesting here because applying the same input a second time will undo the first. Older GUIs used to rely on this for selection highlighting and other overlays, in order to eliminate the need for costly redraws. They're still useful in slow graphics protocols (i.e. remote desktop).

Those were just the first few examples I came up with - this is hardly an exhaustive list.

2 of 16
66

Is it odd?

(value & 0x1) > 0

Is it divisible by two (even)?

(value & 0x1) == 0
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.

🌐
Binaryupdates
binaryupdates.com › home › bitwise operations in embedded programming
Bitwise Operations in Embedded Programming: Detail Explanation
July 13, 2021 - Let’s take variable A and B. We’ll perform bitwise operation on these two variables. This example will help you understand their operation. Let’s first declare these two variables: AND compares each bit and returns 1 if the two bits are 1 (TRUE) otherwise 0 (FALSE). So: C = A & B; The value of C will be 0x12 or in binary 00010010.
🌐
BYJUS
byjus.com › gate › bitwise-operators-in-c
Types of Bitwise Operators in C
August 1, 2022 - The result that we get from a logical operator (&&, ! and ||) is either 1 or 0. But the bitwise operators, on the other hand, return a value that is an integer. Along with this, a logical operator would consider any operand that is non-zero to be 1.
🌐
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.
🌐
Wikipedia
en.wikipedia.org › wiki › Bitwise_operation
Bitwise operation - Wikipedia
1 week ago - In computer programming, a bitwise operation operates on a bit string, a bit array or a binary numeral (considered as a bit string) at the level of its individual bits. It is a fast and simple action, basic to the higher-level arithmetic operations and directly supported by the processor.
🌐
Unstop
unstop.com › home › blog › bitwise operators in c programming with code examples
Bitwise Operators In C Programming With Code Examples // Unstop
July 1, 2025 - Bitwise operators in C programming are tools for performing bit-level operations on integer data. These bit operators, including AND (&), OR (|), XOR (^), and NOT (~), allow programmers to manipulate individual bits within binary sequences/ ...
🌐
Upgrad
upgrad.com › home › blog › software development › bitwise operators in c programming: types and implementation with code examples in 2025
Bitwise Operator in C – Stop Writing Slow Code!
June 11, 2025 - C directly manipulate individual bits within data values. They perform binary level operations, allowing for efficient and low-level data handling. Bitwise operators work by comparing or shifting bits in binary representations of integers.