Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C Exercise 55

C Exercise 55

100 Classic C Language Examples 100 Classic C Language Examples

**Problem:** Learn to use the bitwise NOT ~.

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

Program source code:

Example

//  Created by www.runoob.com on 15/11/9.

// Copyright (c) 2015 Runoob Tutorial. All rights reserved.

//

#include

int

main

(

)

{

   

int

a

,

b

;

    a

=

234

;

    b

=

~a

;

   

printf

(

"The bitwise NOT value of a (decimal) is %d \n"

,

b

)

;

    a

=

~a

;

   

printf

(

"The bitwise NOT value of a (hexadecimal) is %x \n"

,

a

)

;

   

return

0

;

}

The output of the above example is:



Please enter an integer:

a 的按位取反值为(十进制) -235 

a 的按位取反值为(十六进制) ffffff15 

100 Classic C Language Examples 100 Classic C Language Examples