Reverse Modulus Operator

前端 未结 6 726
情深已故
情深已故 2020-12-13 13:54

Over 3 years after asking the question I found the solution. I have included it as an answer.

I have an expression with modulus in it that needs to

6条回答
  •  隐瞒了意图╮
    2020-12-13 14:43

    Using @Subhi Anyman answer as reference (with slight modifications), if we have this equation to reverse the modulus operation

     (var1 + var2) mod num = Res
    

    then to obtain var1, we use the following

    var1 = num - ((Res - var2) * -1)
    if (var1 > num) {
       var1 = var % num;          // making sure var1 is in range of 'num'
    }
    

提交回复
热议问题