I'm writing a program. Part of the program fetches a cryptic memory value from another program (which stores information on a value i'm looking for) and reverse engineers it. I need help figuring out a consistent sequence of commands that i can use to reverse engineer that memory value.
I've confidently determined that that memory value, $y$, is related to what i'm trying to solve for, $x$, by either $y = c_1 + 640a + 16x$ or $y = c_2 + 648b + 16x$.
I know that meaningful ranges for $a$, $b$, and $x$ are $[0, 5]$, $[0, 7]$, and $[0, 39]$ and have determined the values of $c_1$ and $c_2$ beforehand.
If I knew whether it was the first equation or second equation it would simply be a matter of subtracting the constant offset, taking the result module 640 or 648 respectively, and then dividing by 16 to obtain $x$.
But I'm not sure if I can carry out the above on the wrong equation and have an answer that I can toss out ($x$ not being in the range of 0 to 39) every time.
Is there a test i can carry out to determine which equation that memory value belongs to? Or a generic way to solve for $x$? Thanks in advance.