Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
October 8th, 2002, 07:34 AM
Junior Member

Join Date: Jan 2002
Location: New Zealand
Posts: 4
Time spent in forums: < 1 sec
Reputation Power: 0
LZW compression

Hey There!

im wondering if anyone knows the basics of LZW compression and can give me some sample code (in c) of LZW in its most simple form (both encoding and decoding). im trying to get a handle on how it works but all the code i find is quite complex, i need something simple to get me started.

Thanks anyone

richard

#2
October 8th, 2002, 02:02 PM
 M.Hirsch
Contributing User

Join Date: Oct 2000
Location: Back in the real world.
Posts: 5,966
Time spent in forums: 1 Month 2 Days 52 m 24 sec
Reputation Power: 190
LZW is not too hard. But you really should not learn from the code how it works. Code implementations are made for machines to read, not for humans. They probably contain many optimizations (eg. for speed) which make them hard to be read.

The algorithm behind it is afaik "Huffman"-encoding, this is what you should read some theory about. (www.google.com)

Short:
Try to think of a book. In English afaik the letters "e" and "a" are used the most.
In standard ASCII representation any letter uses 8 bits. Why not use only one bit for "e" and "a" like e=0 and a=1? YouŽll save a lot of space then...

The algorithm afaik sorts all letters (any codes, not only letters) by their frequency and puts it into a table (the "key" if you see huffmann as a en/decoding algorithm).
then the most often used one gets the shortest number of bits.

do you understand what i want to say?
__________________
--
Manuel Hirsch - Linux, FreeBSD, programming, administration articles, tutorials and more.

#3
October 9th, 2002, 07:41 PM
Junior Member

Join Date: Jan 2002
Location: New Zealand
Posts: 4
Time spent in forums: < 1 sec
Reputation Power: 0
ok thanks man

 Viewing: Dev Shed Forums > Programming Languages > C Programming > LZW compression