C Exercise Example 55

100 Classic C Examples

Title:Learn to use the bitwise NOT operator ~.

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

Program source code:

Example

//  Created by www.example.com on 15/11/9.
// Copyright © 2015 Example Tutorial. All rights reserved.
//

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

The output result of the above example is:

请输入整数:
a 的按位取反值为(十进制) -235 
a 的按位取反值为(十六进制) ffffff15 

100 Classic C Examples

other extensions