Sorry in advance if I didn't choose the right tags for the question, I wasn't sure.
So I'm a programmer and writing a saving/loading system for data. The way I was serializing (saving) vectors is via creating lists and storing the vector coordinates in those lists. So if I have a Vector3, I save that vector as a list of 3 elements where list[0] is x, list[1] is y and list[2] is z. When loading I just read the values from the list and create a vector from those values.
Then I thought, can't I just somehow convert the vector coords to a number, and just serialize/save that number? and when loading I go in reverse to get the vector?
If the vector's coords are single digits the solution is quite simple. Ex [1, 2, 3] => 123
It gets more tricky if the coords have more digits. I thought about a solution (which currently only works if the coords are integers, not floats) and this is what I came up with:
Given the vector [11, 7, 450] I also flatten the vector, so I get: 117450 and then append that number with 213. where 2 is the number of x's digits, 1 is y's digits and 3 is z's digits. So we get 117450213. Going in reverse is no problem.
My problem is how to deal with float numbers. I can deal with them the same way by storing the number of digits after each decimal place as well. So if we had [7.5, 12.75, 3.25] I'd convert that to 75 1275 325|11 22 12 (the spaces and | are just for clarity). The first 11 represents how many digits x has before and after the decimal point, so 1 before, 1 after. You get the idea. This however could yield large numbers quite easily so imagine a vector [100.32234, 24.24101, 200.5029333] ... yeah... not so great.
I'm sure there's a better way of doing it, so what's the best way to achieve what I want? And, is there an official mathematical term for what I'm trying to do?
Thanks.
Edit: Please note I don't want to store the values in an array, list or anything that allocates memory. That's why I want something to do with numbers and math (CPU effort more than memory)
Any (finite) list of numbers can be encoded as a single number since the "size" of an infinite set $X$ is the same as the size of $X^n = X \times X \times \cdots \times X$.
However, from the practical side of things, your vectors don't really allow for all possible real entries. You are using floating point numbers (or fixed size integers) which only allow for a finite range of values.
Let's say you use a 1 byte floating point numbers (or a 1 byte integer if you like). Then to keep track of a vector with 3 coordinates, you need 3 1 byte floating point numbers. Unless you encode them as a single number, in which case you'll need to use a 3 byte number to encode them. So in the end, there's no memory savings. Plus you have the down side of more complicated code and more processor time.
Your best bet is to stick with an array. Which, in the end, essentially just places the 3 numbers side-by-side in memory automatically accomplishing what you're trying to do anyway. :)
As for a mathematical term, I'm not aware of one - maybe an "encoding". The computer science term would be a "hash function".