View Single Post
  #2  
Old January 2nd, 2009, 10:01 PM
Mush Mush is offline
Super Member
 
Join Date: Dec 2008
Location: Scotland
Posts: 863
Country:
Thanks: 6
Thanked 341 Times in 319 Posts
Mush is a jewel in the roughMush is a jewel in the roughMush is a jewel in the roughMush is a jewel in the rough
Default

Quote:
Originally Posted by icemanind View Post
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?

Last edited by mr fantastic; January 3rd, 2009 at 03:17 AM. Reason: Edited quote to match edit of OP
Reply With Quote