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 Answer from davedontmind on reddit.com
๐ŸŒ
Developerdocs
developerdocs.in โ€บ C โ€บ c_bitwise_operator โ€บ c_bitwise_NOT
Understanding the Bitwise NOT Operator (~) in C: A Beginner's Guide โ€“ Nextra
The bitwise NOT operator (~) in C is a unary operator used to invert all the bits of its operand. It is essential for performing bit-level manipulations and understanding how numbers are represented in binary.
๐ŸŒ
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?

๐ŸŒ
DataFlair
data-flair.training โ€บ blogs โ€บ bitwise-not-operator-in-c
Bitwise NOT Operator in C - DataFlair
October 4, 2023 - In the realm of low-level programming, The Bitwise NOT operator works by flipping each bit of an integer, turning 0s to 1s and vice versa.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ c language โ€บ bitwise-operators-in-c-cpp
Bitwise Operators in C - GeeksforGeeks
The >> (right shift) in C takes two numbers, right shifts the bits of the first operand, and the second operand decides the number of places to shift. The ~ (bitwise NOT) in C takes one number and inverts all bits of it.
Published ย  December 13, 2025
๐ŸŒ
Modulo
ctp.mkprog.com โ€บ en โ€บ c โ€บ bitwise_not
C | Bitwise not: ~ | Easy language reference
Bitwise 1 complement, also known as bit negation or bit-denial operation. operates on the basis of logical negation, if input is 0 then output is 1, and if input is 1 the result is 0. for example you can use it for bit deletion, or bit set to simplify the creation of masks.
๐ŸŒ
Programiz
programiz.com โ€บ c-programming โ€บ bitwise-operators
Bitwise Operators in C Programming
In this tutorial you will learn about all 6 bitwise operators in C programming with examples.
Find elsewhere
๐ŸŒ
Wikipedia
en.wikipedia.org โ€บ wiki โ€บ Bitwise_operations_in_C
Bitwise operations in C - Wikipedia
3 days ago - 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, ...
๐ŸŒ
DataFlair
data-flair.training โ€บ blogs โ€บ bitwise-operators-for-negative-numbers-in-c
Bitwise Operators for Negative Numbers in C - DataFlair
September 29, 2023 - In contrast to sign-magnitude representation, twoโ€™s complement facilitates easy arithmetic operations, making it more suitable for hardware implementations. The unary operator known as bitwise NOT (~) is used to reverse the bit values of a number....
๐ŸŒ
Upgrad
upgrad.com โ€บ home โ€บ blog โ€บ software development โ€บ bitwise operators in c programming: types and implementation with code examples in 2026
Bitwise Operators in C โ€“ Stop Writing Slow Code!
December 6, 2025 - The NOT operator inverts each bit of the value of โ€˜aโ€™(flipping 1 to 0 and 0 to 1). The result is stored in result and displayed. ... The Bitwise Left Shift operator moves all bits of the operand to the left by a specific number of positions. Zeros are added to the right.
๐ŸŒ
StudySmarter
studysmarter.co.uk โ€บ bitwise operators in c
Bitwise Operators in C: Definition & Examples | StudySmarter
... & (AND operator): Performs ... Performs a logical exclusive OR operation on each pair of corresponding bits. ~ (NOT operator): Inverts all the bits of the operand....
๐ŸŒ
Unstop
unstop.com โ€บ home โ€บ blog โ€บ bitwise operators in c programming with code examples
Bitwise Operators In C Programming With Code Examples
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/ ...
๐ŸŒ
Oreate AI
oreateai.com โ€บ blog โ€บ bitwise-not-operator-in-c-language โ€บ ba130228f2820351ab6c6a3fc024eb9e
Bitwise NOT Operator in C Language - Oreate AI Blog
December 22, 2025 - Hereโ€™s an example of using the bitwise NOT operator: #include <stdio.h> int main() { int num = 10; // Binary representation: 0000 1010 int result = ~num; // Bitwise NOT operation printf("The result after bitwise NOT is: %d\n", result); // Output will be -11, binary representation: 1111 0101 return 0; }
๐ŸŒ
BYJUS
byjus.com โ€บ gate โ€บ bitwise-operators-in-c
Types of Bitwise Operators in C
August 1, 2022 - Along with this, a logical operator ... of && and & are different for the very same operands. 4. The bitwise operators should not be used in place of logical operators โ€“...
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ home โ€บ cprogramming โ€บ c bitwise operators
C Bitwise Operators
June 10, 2012 - Explore the C Bitwise Operators, including AND, OR, XOR, NOT, and shift operations with practical examples.
๐ŸŒ
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.
๐ŸŒ
W3Schools
w3schools.com โ€บ c โ€บ c_bitwise_operators.php
C Bitwise Operators
Every integer in a computer is stored in binary, which means it is represented using bits (binary digits) that are either 0 or 1. Bitwise operators allow you to compare, combine, shift, or flip these bits. Note: Bitwise operations only work on integer types (such as int, char, or long).