I would like to represent four floats e.g, 123.545, 56.234, -4534.234, 544.64
using the set of characters [a..z, A..Z, 0..9] in the shortest way possible so I can encode the four floats and store them in a filename. What is the most efficient to do this?
I've looked at base64 encoding which doesn't actually compress the result. I also looked at a polyline encoding algorithm which uses characters like )
and {
and I can't have that.
You could use the
struct
module to store them as binary 32-bit floats, and encode the result into base64. In Python 2:The == padding can be removed and re-added for decoding such that the length of the base64 string is a multiple of 4. You will also want to use URL-safe base64 to avoid the / character.