Quick actions

cmd+k|ctrl+k

Navigation

Languages

Ones complement Operator

Snippet info

Language

C

Visibility

public

Author

krishnakanth

Created

2022-11-18T05:40:56.850605Z

Updated

2022-11-18T05:42:17.775114Z

// 2’s Complement:
// Two’s complement is an operation on binary numbers. The 2’s complement of a number is equal to the complement of that number plus 1. 

// Example:

// Bitwise complement Operation of 2 (~ 0010 ): 1101

// Calculate 2’s complement of 3: 
// Binary form of 3 = 0011 
// 1’s Complement of 3 = 1100 
// Adding 1 to 1’s complement = 1100 +1
// 2’s complement of 3 = 1101  

// Note: 
// The bitwise Complement of 2 is same as  the binary representation of -3 

#include <stdio.h>

// Driver code
int main()
{
int n = 2;
printf("Bitwise complement of %d : %d",
		n, ~n);
return 0;
}
INFO