Excellent! I made one mistake, I took 7f7f as a whole in its decimal value (32639) which obviously is wrong. I need to understand a bit better the conversion of hex pairs to decimal.
But now the posted formula above works for all parameters, -12/12, -50/50 or even -99/99.
Thank you again!