Easy Tutorial
❮ C Examples Source Code Output C Function Fread ❯

C Practice Example 55

C Language Classic 100 Examples

Title: Learning to use bitwise NOT ~.

Program Analysis: ~0 = -1; ~1 = -2;

Program Source Code:

Example

// Created by www.tutorialpro.org on 15/11/9.
// Copyright © 2015 tutorialpro.org. All rights reserved.
//

#include <stdio.h>
int main()
{
    int a, b;
    a = 234;
    b = ~a;
    printf("The bitwise NOT of a in decimal is %d \n", b);
    a = ~a;
    printf("The bitwise NOT of a in hexadecimal is %x \n", a);
    return 0;
}

The output of the above example is:

Please enter an integer:
The bitwise NOT of a in decimal is -235
The bitwise NOT of a in hexadecimal is ffffff15

C Language Classic 100 Examples

❮ C Examples Source Code Output C Function Fread ❯