programming forums Java Java JSRs Mobile Certification Databases Caching Books Engineering OS Languages Paradigms IDEs Build Tools Frameworks Products This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Sheriffs:
Saloon Keepers:
Bartenders:

# Ten's (not Two's) Complement

Marlene Miller
Ranch Hand
Posts: 1392
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
Posts: 4313
does this have anything to do with Certification?

Marlene Miller
Ranch Hand
Posts: 1392
Yes.

Corey McGlone
Ranch Hand
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.