66. Detect Underflow in Unsigned Subtraction

You are given two 8-bit unsigned integers a and b. You must compute a - b, and also detect if underflow occurred (i.e., when b > a).

Return:

  • The result of a - b (with wraparound if any)
  • A flag carry = 1 if underflow occurred, otherwise carry = 0
     

Example-1

Input: a = 100, b = 50
Output: diff = 50, carry = 0

 

Example-2

Input: a = 10, b = 20
Output: diff = 246, carry = 1

 

Example-3

Input: a = 0, b = 0
Output: diff = 0, carry = 0


 

Loading...

Input

100 50

Expected Output

diff = 50, carry = 0