This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Ten's (not Two's) Complement Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Ten Watch "Ten New topic
Author

Ten's (not Two's) Complement

Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
This is an essay on Ten�s (10�s) Complement.
Lesson 1.
There are 10000 4-digit numbers, from 0000 to 9999.
Take the second half of those numbers (5001 to 9999) and designate them as the negative numbers of the first half (1 to 4999). The number 5000 is a problem.
Which number from the second half shall represent the negative of a number from the first half?
0000
0001 + 9999 == 10000
0002 + 9998 == 10000
0003 + 9997 == 10000
...
1234 + 8766 == 10000
...
4997 + 5003 == 10000
4998 + 5002 == 10000
4999 + 5001 == 10000
5000
Notice that 1 + 9 == 2 + 8 == 3 + 7 == ... == 4 + 6 == 10.
Notice that 1 + 9999 == 2 + 9998 == 3 + 9997 == 4999 + 5001 == 10000.
We define the negative of x to be 10000 � x.
Lesson 2.
The negative of x is 10000 � x.
Let y be the negative of x.
y = 10000 � x = 9999 � x + 1.
To get the negative of a number, it is often easier to subtract each digit from 9 and then add 1.
Lesson 3.
-0 = 10000.
To get the negative of 0, we subtract from 10000 as always and then drop the overflow high-order 5th digit. -0 == 0.
Lesson 4.
Notice that the high order digit of a negative number is always 5,6,7,8 or 9. The high order digit is often called the sign digit.
-5000 = 10000 - 5000 = 5000.
The negative of 5000 is 5000. 5000 has no positive number.
[ October 09, 2003: Message edited by: Marlene Miller ]
Jessica Sant
Sheriff

Joined: Oct 17, 2001
Posts: 4313

does this have anything to do with Certification?
Marlene Miller
Ranch Hand

Joined: Mar 05, 2003
Posts: 1391
Yes.
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
That is a nice essay, Marlene and I understand the underlying meaning of this with regards to 2's complement (or 10's or whatever base, I suppose), but this level of theory is certainly not required for the exam. That's great that you want to drill down to this level of detail but, like I said, it's not required for the exam - I'm going to move this to Java in General, Intermediate.
In short, this is a nice explanation for having one extra "negative" value than "positive" value, such as a byte ranging from -128 to 127.


SCJP Tipline, etc.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ten's (not Two's) Complement
 
Similar Threads
Hexadecimal to decimal
~operator
Bits & Bytes
print same values?
~ operator