Comparison of signed 16bit values from addition orsubtraction
Nikolai Golovchenko email (remove spam text)
Walter Banks wrote:
> This is the technique used by most compilers (including MPC) on
> processors that do not have an overflow bit for comparing
> signed numbers.
Cool, I didn't know that.
> Careful implementation can also use this
> technique for comparing signed and unsigned numbers of the
> same number of bits without casting to a larger number of bits.
Let me guess. If the most significant bit of the unsigned number is
set, than it's bigger and you quit. If not, the sign bits are inverted
for both numbers and then compared as if they are both unsigned.
I think you can even do some math using the biased representation. It
is probably not much different from the usual unsigned, if you track
the bias value. Interesting, is someone using that representation for
more than just comparison?
> The nice thing about using a biased representation to
> do the comparison is that exclusive or can be used to add the
> bias to the number (or invert the sign bit) This is important
> because in most compact implementations the carry bit needs
> to be preserved during at least one one of these operations.
> Walter Banks
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics
In reply to: <3AA8BF39.A5ED4417@bytecraft.com>
See also: www.piclist.com/techref/microchip/devices.htm?key=pic
You must be a member of the
piclist mailing list
(not only a www.piclist.com member) to post to the