Arithmetic Coding Algorithm with Scaling
C(a1) = 0, C(a i+1) = C(ai) + P(ai) for 1 < i < m
Maintain an interval [l,r), initially [0,1)
if [l,r) contained in [0,1/2) or [1/2,1) then scale:
- [0,1/2) then output 0; l := 2l; r := 2r
- [1/2,1) then output 1; l :=2(l-1/2); r := 2(r-1/2)
otherwise process symbol x
- w := r - l; l := l + w C(x); r := l + w P(x)
if no symbols left and l < 1/2 < r left then send significant bits of tag for interval [l,r).