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 (~) inverts each bit of its operand. In signed integers, ~x is equivalent to -(x + 1). It is widely used for one’s complement, bit masking, and bit-level operations.
🌐
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?

🌐
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
🌐
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.
🌐
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
4 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.
🌐
IBM
ibm.com › docs › en › zos › 3.1.0
Bitwise negation operator ~
We cannot provide a description for this page right now
🌐
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; }
🌐
Fresh2Refresh
fresh2refresh.com › home › c programming tutorial › c – operators and expressions › c – bit wise operators
Bit wise operators in C | C Operators and Expressions | Fresh2Refresh
September 24, 2020 - Bit wise operators in C language are & (bitwise AND), | (bitwise OR), ~ (bitwise NOT), ^ (XOR), << (left shift) and >> (right shift).
🌐
GNU
gnu.org › software › c-intro-and-ref › manual › html_node › Bitwise-Operations.html
Bitwise Operations (GNU C Language Manual)
As in the previous section, the examples in this section use binary constants, starting with ‘0b’ (see Integer Constants). They stand for 32-bit integers of type int. ... Unary operator for bitwise negation; this changes each bit of a from 1 to 0 or from 0 to 1.
🌐
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.
🌐
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).