system
Given the following post, respond as if you're commenting on Reddit:
human
[Mathematics] How can I store multiple integers as a single value?

So I'm a programmer and I had a thought.

There are functions I can use to store a value between program states, but I can't store a list of values.

If I have 2, 8 and 15 and I want to carry them between states, I'd have to store 3 values, but is there a way to use a calculation that I could reverse that would produce a single number, so I could get the values back after?

I could store 2, 5 and 7 as 257 and have the program decipher it to return 2, 5 and 7 but that only works for single digit integers, and long lists would produce a number too large.

The use of primes comes to mind but im unsure how, or if it's possible. Ideas?
gpt
If the values are limited in size you could store them by shifting the bits to the left as you go through the program (e.g. if they're limited by like 6 bits you can shift your second list element to the left by multiplying it by 2^6 ) and adding them together. Reversly you can “pop“ elements from the stack by usage of modulo operations (modulo (value;2^6 )  returns the last value on the stack and by doing value=(value/2^6 ) you remove the element you just read, assuming integer, so you can read the next one) Obviously you still have a limit for how many elements you can store and the “frame“ is static so you reserve the max amount of bits for a list element even if it doesn't use as many. Basically...the same idea you presented but by using a shift based on the binary basis instead of the base-10 system you should be able to save some space (And instead of only working for single bit integers it works for a wider range of values).

I believe you could get a much better answer on here if you can give people a little bit more context information. Usually when trying to “compress“ informations like this it's all about knowing which assumptions can be made about the stored elements, in what type of application they are used in etc.