Latest web development tutorials

C Exercise Example 55

100 cases of classic C language 100 cases of classic C language

Topic: Learn to use bitwise ~.

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

Source Code:

//  Created by www.w3big.com on 15/11/9.
//  Copyright © 2015年 本教程. All rights reserved.
//

#include <stdio.h>
int main()
{
    int a,b;
    a=234;
    b=~a;
    printf("a 的按位取反值为(十进制) %d \n",b);
    a=~a;
    printf("a 的按位取反值为(十六进制) %x \n",a);
    return 0;
}

The above example output is:

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

100 cases of classic C language 100 cases of classic C language