Re: Working with negative numbers
- From: "Bill Pursell" <bill.pursell@xxxxxxxxx>
- Date: 28 Jun 2006 12:01:53 -0700
pete wrote:
Bill Pursell wrote:
Frederick Gotham wrote:
(1) Sign-magnitude: The bit-pattern is exactly the same.
(2) One's complement: Toggle each bit.
(3) Two's complement: Toggle each bit, then add 1.
This has always sort of bugged me. The description of
2's complement above is a nice way to describe the
technique for comprehending the bit pattern used to
represent an integer, but it's not a good way to describe
the system. I think a better description is: take the top
half of the unsigned integers and move them to the bottom.
Unfortunately, I can't find the right wording to explain
that description completely. Any thoughts on expanding
it sufficiently to describe it, without making it too verbose?
signed magnitude is taking the top half
of the integers, flipping them over and moving them to the
bottom, with the zeros overlapping. (From this description,
it's far more obvious why 2's complement is simpler.)
One's complement is derived by moving the top half
to the bottom and shifting up by one to make the zeros
overlap.
It feels like those descriptions are not clear to the clueless
newbie, however. I'm not sure they're even clear to anyone
unless they already understand the number system...
I already understand the number system.
I don't understand the following terms:
"top half of the integers"
"moving them to the bottom"
By "top half of the unsigned integers", I mean those
values with the MSB set. I'm picturing the values stacked
up with 00..00 on the bottom and 11..11 on the top and
the number line to the right of the stack, with the number
line aligned in such a way that each bit collection is next
to it's usual interpretation. So negative values and those
above UINT_MAX have nothing to the left of them. Now
grab the top half of the stack and move it down so that
11..11 is to the left of -1. It's a graphic that I can see clearly
in my head, but I don't think I've ever described it accurately
enough to explain it to anyone that didn't already grok. Maybe
it's just a bad description....
.
- References:
- Working with negative numbers
- From: Frederick Gotham
- Re: Working with negative numbers
- From: Bill Pursell
- Re: Working with negative numbers
- From: pete
- Working with negative numbers
- Prev by Date: Re: Order of execution
- Next by Date: Re: qsort() results: implementation dependent?
- Previous by thread: Re: Working with negative numbers
- Next by thread: Re: Working with negative numbers
- Index(es):
Relevant Pages
|