For $x = p/q$, where $x$ is a known value between $0.000$ and $1.000$ rounded to the thousandths place, $p$ is an integer value between $0$ and $127$, and $q$ is an integer value between $0$ and $255$: what is $p$ and $q$? Or rather, how does one find all the possible ratios of $p$ and $q$ within these constraints that equal $x$?
For example, in the case that $x = 0.523$.
(I know the following because of excel)
$p=56$ and $q=107$; $56/107 = 0.52336448598 = 0.523$
$p=57$ and $q=109$; $57/109 = 0.52293577982 = 0.523$
$p=58$ and $q=111$; $58/111 = 0.52252252252 = 0.523$
How do I find $p$ and $q$ knowing only $x$ and the constraints of the problem?
That's the best i can phrase the problem in order for it to be appropriate for a mathematics forum. However, I figured it might be helpful to provide the context even though the details may be considered a little removed from the focus of this forum:
I have two digital rheostats arranged as a voltage divider that need to be written to so that the desired voltage at $V$-OUT is provided. I'm trying to find a way to algorithmically arrive at the values to which $R_1$ and $R_2$ should be set.
1.000V | | .----- V-OUT | / ||| / R1 |||<-----,-------X ||| | ||| R2 |||<-----, ||| | | | GND
$V$-OUT is $x$, $R_1$ is $p$, and the total resistance $(R_1+R_2)$ is $q$.