Advertisement

Base24 Encoding Algorithm

Started by June 14, 2001 10:02 PM
0 comments, last by Gavin Thomson 23 years, 8 months ago
I''m fine conceptually will base64/32/16/8 etc coding.. But I''m not sure how to go about a more general algorithm for say base24 or base5 encoding of a byte stream.. Any ideas or hints would be greatly appreciated...
Ok it''s 2 AM and I''m bored, so here''s my idea for how to create a stream of base5 digits. Basically you end up using 3 bits per digit, as if it were base8, but every 15 or so bits you''ll manage to store an extra base5 digit "for free".

Start by creating a lookup table which associates each base5 digits with 1 or 2 base8 digits:

0 => 0
1 => 1 or 2
2 => 3
3 => 4 or 5
4 => 6 or 7


Now, take each base5 digit from your source, use the lookup to produce a base8 digit, and add the base8 digit to your stream.

But, if the base5 digit was 1, 3, or 4, you have some flexibility (a 1 can be stored as a 1 or a 2). Basically you have a free bit. But just remember this point in the stream for now, and continue.

After eventually coming across two more points like this, stop. Take your next base5 digit, and use these last 3 free bits to store it. Now you can actually transmit/flush the stream up to this point, since you won''t be modifying any more previous portions of the stream.

As you can probably imagine, this process could be generalized for digits of any base (just find the nearest, greater power of 2 to use for the lookup).

This topic is closed to new replies.

Advertisement