Quote:
Originally Posted by icemanind Okay, this will be pretty elementary, I'm sure. But for some reason, I am having trouble. I am trying to write a program and I am using the following formula:
Offset = Y * 160 + X * 2
This formula works great for what I'm doing. My question is, what is the formula I use to retrieve X and Y, assuming I know Offset. For example, if Offset = 1500, what is the value of X and Y?
If it helps, what this is is X and Y coordinates for video memory. Video memory is broken down into 80x25 characters and each character takes 2 spaces.....So if I want to write to Y=10 and X=5, using my formula above, the offset to write to would be 1610.
So my question is, given 1610 as an Offset, what formula do I use to make Y=10 and X=5?
Hope this makes sense and thanks in advance
Alan |
So you're asking us to solve an equation with 2 variables? Unfortunately it's not possible to solve for 2 unknowns unless you have 2 equations.
However, if X and Y are restricted to integer values then your equation is a linear diophantine equation (ax+by=c), and these can be solved using the Euclidean Algorithm if c is the greatest common divisor of a and b (or indeed a multiple of the greatest common divisor!) Do you know the algorithm?