by Dinesh Thakur Category: Operators and Expressions

The **bitwise complement operator** (~), which perform a bitwise negation of an integer value. Bitwise negation means that each bit in the number is toggled. In other words, all the binary 0s become 1s and all the binary 1s become 0s.

x = 8;

Y = ~x;

Integer numbers are stored in memory as a series of binary which can be either 0 or 1. A number is considered negative if the highest order bit in the number is set to 1. Because a bitwise complement converts all the bits in a number including the high order bit (sign bit). Since the number becomes negative, it is in 2's compliment form. To know its decimal value, first we will subtract 1 from the number and then perform l's compliment onto it (i.e. convert 1 to 0 and 0 into 1).

Here is the Java Example for **Bitwise Complement Operator**:

class BitwiseComplementOperator

{

public static void main (String args[ ] )

{

int x = 8 ;

System.out.println("x = " + x);

int y = ~x;

System.out.println ("y = " + y);

}

}

About Dinesh Thakur

Dinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Search Content

Popular Article

#### Constant - What is Constant? Type of Constant

#### Java Operator

#### What is Identifiers,Literals,Operator and Separators

#### Shift Operators in Java Examples

#### Logical Operators in Java Examples

#### Assignment Operator in Java Example

#### Conditional Operator in Java with Example

#### Bitwise Complement Operator Example in Java

#### Increment and Decrement Operators in Java Examples

#### Arithmetic Operators in Java Examples

#### Explicit Type Conversion (Type Casting)

#### Bitwise Operators in Java Example

#### Bitwise AND, OR, and XOR Operators in Java Example

#### Relational Operators in Java Example

#### Implicit Type Conversion in Java Example

#### Java Break Statement with Label Example

#### Mathematical Operations in Java Example

#### Compound Assignment Operators in Java Example

#### Java Continue Statement Example

#### Area of Triangle in Java Example

#### Java Arithmetic Operators Example

#### Java Continue With Label Example

#### Break Statement Java Example

#### Comparison Operators in Java Example

#### Java Break Statement Example

Basic Courses

Advance Courses