Bit Not Operator - C Operator

C examples for Operator:Bit Operator

Introduction

The unary operator, ~, flips the bits of its operand, so 1 becomes 0, and 0 becomes 1.

Demo Code

#include <stdio.h> 

int main(void) { 
    /*from   www .jav  a 2s  .  c  om*/
    int x = 13;
    int y = 6;
    int z = ~x;                            // Store 1's complement of x
    
    printf("%d",z);
    return 0; 
} 

Result

After executing this statement, z will have the value 14. The bits are set as follows:

x          0       0       0      0      1       1       0       1
~x         1       1       1      1      0       0        1      0

Related Tutorials