There are 2 types of integers, signed and unsigned.
For all signed integers the high/top bit is sign where if that bit is 1 the value is negative and if it's 0 the value is positive.
WHAT value? That's what the Twos Complement is about.
16 bit signed integers can count from -32768 to +32767.
For unsigned integers there is no sign bit.
16 bit unsigned integers can count from 0 to 65535.
If you subtract 16 bit unsigned 1111111110011000 (dec 65432) from unsigned 65536 you get 104 and the sign bit tells you iot is -104..
Bitmath Tutorial - use the power of bits to save cpu cycles and RAM.
Above example this binary number is 104 this is the confusing part.
It is decimal -104 as in 0 - 104 = -104.
Binary 104 is 0b1101000 and binary -104 is 0b1111111110011000.
Add the binary values in 32-bit integers and you get 0b10000000000000000, 1 bit higher than 16.
With unsigned integers we calculate TIME DIFFERENCES. If I subtract a start time from an end time, even if the end time is "rolled over" past 0 the answer will be right because of unsigned subtraction. it is like how between 10 and 2 on a round 12 hour clock is 4 hours -- from 2 backward for subtract 10 leaves us on 4, the hours between 10 and 2 as clock/unsigned 2 minus/backwards 10.