C Exercise Example 55
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;
}
// 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 的按位取反值为(十六进制) ffffff15other extensions