I am writing my own Servo Driver Program in Python and I struggle quite a bit with Two's (2's) Complement calculation.
Example: I want to have "-100" as an input and get "FF9C" or just "9C" which would also work for the output.
The following picture might help to clarify:

hex(-100 & 0xffff) == '0xff9c'andhex(-100 & 0xff) == '0x9c'. This of course works with other negative numbers, too.n = -100 ; print(f'hex "{n:x}" ; two complement: "{n&(2**16-1):x}"')->hex "-64" ; two complement: "ff9c"