I am looking for a streaming algorithm for converting a decimal number to a hexadecimal number. I am assuming the input is a string represention of a decimal number (i.e., each character is a decimal digit) in digit-reversed order, and I'd like the output to be a string represention of a hexadecimal number (i.e., each character is a hex digit) in digit-reversed order.
By streaming, I mean that I'd like the algorithm to start producing hexadecimal digits without having to look at the entire decimal-string input first (i.e. up to some fixed number of digits of input can be looked at before producing digits of output); and ideally with only a constant amount of memory.
Is there a way to do this?
I know one can convert from hexadecimal to binary in a streaming way. For single-digit numbers, we can use the following table:
hex -> bin 0 -> 0000 1 -> 0001 2 -> 0010 3 -> 0011 4 -> 0100 5 -> 0101 6 -> 0110 7 -> 0111 8 -> 1000 9 -> 1001 a -> 1010 b -> 1011 c -> 1100 d -> 1101 e -> 1110 f -> 1111
For multiple-digit numbers, we can do the same by applying the mapping above to each hexadecimal digit individually.
1234 -> 1, 2, 3, 4 -> 0001, 0010, 0011, 0100 -> 0001001000110100
Is there a way to do something like this, converting from decimal to hexadecimal?