http://en.wikipedia.org/wi

Solved

Posted on 2009-02-19

Hi,

having (infinite) stream of bytes from LSB, how can I produce (infinite) stream of decimal numerals? The stream of bytes represents an extremely big integer number. The decimal numerals represent decimal representation of the number.

Thanks,

Petr

P.S. whatever language, pseudocode i OK. I am just somehow stupid after the lunch ;)

having (infinite) stream of bytes from LSB, how can I produce (infinite) stream of decimal numerals? The stream of bytes represents an extremely big integer number. The decimal numerals represent decimal representation of the number.

Thanks,

Petr

P.S. whatever language, pseudocode i OK. I am just somehow stupid after the lunch ;)

14 Comments

here is one possible algorithm

http://en.wikipedia.org/wiki/Arithmetic_coding

http://en.wikipedia.org/wi

Arithmetic coding can give you a representation, but the final decimal numerals when interpreted as a decimal number may not be the same number as the stream of bytes interpreted as a base 256 number.

You could also represent the bytes using only the decimal numerals from 0 to 7

To ozo, I could say the same when having the stream of bits. I really want to get the numerals from 0 to 9 that, when concatenaded, would represent the number like a*10^0 + b*10^1 + c*10^2 + ...

In other words, I want to accept numerals in one encoding (here base 256) and produce the numerals in another encoding (here base 10). What is important, I want to do that on-the-fly. If the input stream ends, it is possible to accept extra zeros until I am sure that the internal state of the algorithm can produce also only zeros on output.

The only way out, is to send the bytes in blocks representing values that are a power of 10. For example, each block of 4 bytes represents values between [0, 1000000000[ only. Any value outside of that range is an error. This limits the throughput of the stream, but it allows you to generate the decimal representation on-the-fly (per block of x bytes).

> the next byte (bit) on the stream can modify any and all of the decimal digits.

with

> If the input stream ends, it is possible to accept extra zeros

and ones

> until I am sure that the internal state of the algorithm can produce also only zeros on output.

then we may be able to represent a decimal number that start with the output corresponding to a binary that starts with the input, (but not necessarily continuing with all 0's)

It's actually easier to do this if the numerals from 0 to 9 that, when concatenaded, would represent the number like a*10^-0 + b*10^-1 + c*10^-2 +

and the numerals from 0 to 1 that, when concatenaded, would represent the number like a*2^-0 + b*2^-1 + c*2^-2 + ...

(but you can also think of them as being scaled by an appropriate power of 2 or 10)

To avoid having to do all calculations in infinite precision, arithmetic coding effectively allows a bit of fudging in the 10^-n and 2^-m values. while maintaining the correspondence between input and output.

Basically, I have a (large) buffer of bytes and I want to decide later how many decadic digits I want to get.

If you (both) have any idea how to do that, we can formulate the question and I will ask it (as a new one). I will ask it anyway. You can just suggest... You know ;)

That's possible, if you know the length of the stream. ie. you need to know the bit position of that MSB. If you know that, you can progressively determine the most significant decimal digit first, etc.

For me, there's no need to open a new question. If you want, you can re-open this one :)

See http:Q_24161121.html

P.S. When having "unlimited" account, I prefer to spend. I wish I could do that with money :D

By clicking you are agreeing to Experts Exchange's Terms of Use.

Title | # Comments | Views | Activity |
---|---|---|---|

Accurate distance between two GPS coordinates | 2 | 930 | |

How to Add same Index Array Elements in Octave | 2 | 300 | |

How to Transpose data in Excel through formula or code? | 13 | 245 | |

How to update multiple binary circular files in C | 3 | 213 |

This video discusses moving either the default database or any database to a new volume.

Join the community of 500,000 technology professionals and ask your questions.

Connect with top rated Experts

**7** Experts available now in Live!