I was having a similar problem and being quite stubborn I was convinced there was a mathematical solution to this and I found one that works for me.
My problem was storing a bunch of x,y coordinates into a flat list that I could easily reference. I though of the two main ideas posted here and was about to give in to bit shifting when I found something you may be able to put to use. The trick is simple, use a prime number in the equation;
number = x + prime * y
hope this helps.