Simple Text Compression

General FreeBASIC programming questions.
Post Reply
mrminecrafttnt
Posts: 131
Joined: Feb 11, 2013 12:23

Simple Text Compression

Post by mrminecrafttnt »

I will try to write an simple text compressionalgorythmm, allowed are letters from A...Z the idea is to reduce the 8bit per char to 5bit(theoretical will it reduce an "Hallo World" from 11byte to 5byte but i have no idea how to compress and decompress it.
The example codes should be usefull... :)

Edit: This idea is not new it based on the Baudot code
https://en.wikipedia.org/wiki/Baudot_code

And i found some Examplecode in C
https://github.com/silizium/baudot
Stonemonkey
Posts: 649
Joined: Jun 09, 2005 0:08

Re: Simple Text Compression

Post by Stonemonkey »

'Hallo World' has upper and lower case which would require switching between the character sets so requires a few extra bits in the string, how many extra bits depends on how many sets you have, also, reducing each character size from 8 to 5 bits won't reduce 11 bytes to 5, it'll be just under 7 bytes if there's no switching.
Easiest way I can think of encoding that would be to have some function that you can stream bits into that then adds those bits into an array of some integer type 1 bit at a time and it fills up each integer and moves onto the next.
Stonemonkey
Posts: 649
Joined: Jun 09, 2005 0:08

Re: Simple Text Compression

Post by Stonemonkey »

And, say you have 4 character sets, then each switch would require 7 bits so 'Hallo World' would require 11*5+4*7=83 bits as opposed to the 88 bits that are required for 8 bit characters.

Edit: sorry, I was getting a little mixed up with how it switched between the sets, the switch is 5 bits and there's only 2 sets, and only upper case.
Post Reply