
formula
Hi, I was just wondering if it is possible to take two numbers or digits, and process them in such a way in that the result will allow you to extract them two digits and/or numbers again.
For example, say you have 31 and 49 and the result of the formula applied to them was 456. Is there a formula in existence that can be applied to them two numbers so you can get them back again?
Thanks, for any feedback.

yes exactly thanks. Tell me, where did you learn that formula from? Is just experience in programming?

it depends on what your original formula is... it's just algebra... the reverse formula he gave you would only work for the original formula he used or a variation of that...

Whats your initial formula

The simplest formula for two numbers, a and b, where a has a defined maximum value, would be
Code:
combinedValue = a + [ b * ( maxValue( a ) + 1 ) ]
Then, to go the other way:
Code:
a = combinedValue modulo maxValue( a )
b = floor( combinedValue / maxValue( a ) )

Of course, the most compact formula you can come up with to combine two distinct numbers and then retrieve them is XSquared's, but it suffers from the fact that it only works on bounded numbers, and can quite easily run into overflow problems.
If you know one of them however,
combined = x ^ y;
... and then ...
x = combined ^ y; ... or ...
y = combined ^ x;

Heh. I completely forgot about XORing things. In my opinion, its much, much better than my previously posted algorithm, because the combined value is always going to be within the data type's bounds.

if you wana get more complex you can have the first digit represent a key to the formula. which is applied during creation and is randomly created. that way you can realy have it hard to figure out. Again we just need your formula