# Signed hex subtraction vs unsigned

I need to do a subtraction on two signed 16 bit hexadecimal numbers. C352 - 36AE. What is the difference between signed and unsigned when it comes to math with them? Is this the only solution converting them to binary, doing subtraction with the captions, and then converting the response back to hex? Thank.

+3

source to share

The subtraction is the same for both signed and unsigned. Another thing is how to interpret the results. Unsigned numbers can never be negative:

0xffff is -1. 0xffff - 65535 unsigned.

This is the same number.

+1

source

The result of a 16-bit unsubscribed or unsigned subtraction is always 16 bits (which is the result of a bitwise subtraction) plus the 17th bit, with the 17th bit being either the overflow bit (subtraction by subscription) or the carry bit (unsigned subtraction), If you only have 16 bit result, you have bitwise subtraction NOT signed or unsigned 16 bit subtraction. Instead of specifying signed, unsigned, or bitwise subtraction, many systems produce all three results at once. Later, you use the overflow bit if you intended to write off the subtraction, the carry bit if you intended to subtract unsigned, or neither for bitwise subtraction. Note that many people don't look at the 17th bit because they know from the range of inputs that they don't need true 16-bit subtraction. For example,if I subtract a number that I know is between 0 and 100 from a number that I know is between 1000 and 2000, I don’t need a true 16-bit subtraction, so I don’t need to look at the 17th bit , Note. Overflow and carry over are done differently and are NOT the same, but the difference between the two has already been explained elsewhere, so I won't duplicate that answer here.

+1

source

All Articles