This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Hi, I have an int x = 5; 0000 0000 0000 0000 0000 0000 0000 0101 ~x converts to: 1111 1111 1111 1111 1111 1111 1111 1010 Now, x = -6 WHY??? I know that the 32th digit represents the -ve sign. How to compute the number "6"? Thanks for help. Andrew
Now you got me worried that you don't understand... All you need to do is get the two's complement: 1. complement the number 2. add 1 If you start out with a negative number, you will get its positive and vice versa. The way you showed it would be way too long unless you've memorized all the powers of 2 and can add really fast. I'm not even sure it'll give you the right result for all, if any, numbers.