Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Paul Clapham
• Ron McLeod
• Bear Bibeault
• Liutauras Vilda
Sheriffs:
• Jeanne Boyarsky
• Tim Cooke
• Junilu Lacar
Saloon Keepers:
• Tim Moores
• Tim Holloway
• Stephan van Hulst
• Jj Roberts
• Carey Brown
Bartenders:
• salvin francis
• Frits Walraven
• Piet Souris

# Question on Bitwise Complement Operator

Ranch Hand
Posts: 49
• Number of slices to send:
Optional 'thank-you' note:
Here is the copy/paste from K&B Book for SCJP 1.4

The ~ operator is a flip-the-bits operator. It will change all 1s to 0s and vice versa.
Look at the following code:

This program is changing every bit into its complement; thus, the output from this program is the following:
%java Bitwise
x is initially 5
~x is equal to -6
In bit representation, the conversion looks like this,
~0000 0000 0000 0000 0000 0000 0000 0101
and converts to
1111 1111 1111 1111 1111 1111 1111 1010

My Question is how this value 1111 1111 1111 1111 1111 1111 1111 1010 is equal to -6 Some please explain me..

Ranch Hand
Posts: 2023
• Number of slices to send:
Optional 'thank-you' note:
1111 1111 1111 1111 1111 1111 1111 1010 = -6 is one of binary negative presentation.