How to convert infinite stream of bytes to infinite stream of decadic numerals?
Posted on 2009-02-20
I need to convert theoretically inifinite stream of bytes into the stream of decadic numerals 0-9. (Practically, you do not know how many bytes you get and you cannot wait until all of them come.)
This taks is easy if you want to produce stream of hexadecimal numerals. This is because every 4 bits can be directly expressed as on hexa numeral. The same probably cannot be done simply with decadic numerals, because there is no natural bit boundary related to decadic numerals.
On the other hand, I do not need reversible conversion. In other words, I do not need the output stream be ever converted back to the original. The output need not to have the features of a number with the same value as input.
For example, it would be nice to be able to convert one byte into a number 0-99 (which obviously mean some loss of the information). However, I want the numbers 0-99 appear with the same probability. For example "byte modulo 100" is not acceptable because the values 0-55 appear with higher probability then the numbers 56-99 (if the input bytes are random).
To be even more specific, I have a stream of bytes that comes as a kind of signature (but I do not know the size in advance). I know that I want say 4 couples like 01 23 45 67 (or 8 couples, or...).