I need to binarily encode/decode small integers (around 10 bits), in such a way that the hamming distance of the encoded number grows monotonically with the (absolute value) arithmetic distance of the numbers.
Edit: the monotonicity doesn't needs to be absolute. There is probably a cost to pay breaking it, but the cost should be as low as possible. Is preferable to reduce the hamming distance at short scales, and if unavoidable, break it at larger scales.
The question is: Is there already such an encoding (better if it has error correction)?
I need to use it in python, so if there is already a python library to do the encode/decode, it would be perfect.
The "monotonically growing" requirement is a loose requirement. It is not strictly necessary. It just is convenient that the hamming distance reflects the arithmetic distance in some way.
The hamming distance can be replaced wit some other measure of encoding distance, like Jaccard distance.
The requirement is that close integers share most of their binary encoding, and still there is error correction.