Page 1 of 1

gpBinEncode - General Purpose Binary Encoding

Posted: 18 Aug 2015, 09:46
by Alibaba
Hey guys,

I was playing around with binary encoding a little bit in the last time, thus i was incidentally creating a little help library, which i want to share with you.
Like the topic title is saying, this library contains a function "gpBinEncode()", which allows you to put any data through any binary coding with fixed sourcewords and codewords in a serial manner.
This means for example (amongst other codes): parity codes, shannon-fano- or huffman-optimal-coding, hamming codes, cyclic codes, ...
Additionally you'll find 2 help functions "gpLoadBinString()" / "gpStoreBinString()" to read and write binary data of any length into/from the memory. This was espacially usefull for me, when testing different codings with gpBinEncode().
Another function "gpApproxAverageLength()" is simply used internally for some kind of optimization. It approximates the average code word length from a given encoding table.

The full range of functions:
gpBinEncode(ByRef sourceData, ByRef encodedData, encodingTable, sourceLength="StrLen", ByRef leftoverData := "omitted", ByRef leftoverLength := "")
gpStoreBinString(ByRef var, binString)
gpLoadBinString(ByRef var, length)
gpApproxAverageLength(encodingTable)

The library (with a short documentation for each function):
gpBinEncode.ahk

3 simple examples: (you could question the real applicability of these examples, but they give a good quick summary of the libraries functionality ;) )
Examples.ahk
I'm happy over any feedback!
Greetings, Alibaba

Re: gpBinEncode - General Purpose Binary Encoding

Posted: 18 Aug 2015, 09:58
by Alibaba
Oh btw, gpLoad/StoreBinString is BigEndian -> the byte with the msb is at the smallest adress

Re: gpBinEncode - General Purpose Binary Encoding

Posted: 18 Aug 2015, 18:09
by Alibaba
Update to v0.2:
-fixed approxAverageLength() function, that did something completely different than described in its documentation, sorry :D

Re: gpBinEncode - General Purpose Binary Encoding

Posted: 19 Aug 2015, 22:36
by BGM
Ali, pardon me for asking, but what would you use this for? Onoce or twice in some math operations dis I use bitshifting.

Re: gpBinEncode - General Purpose Binary Encoding

Posted: 20 Aug 2015, 16:33
by Alibaba
No problem, thanks for asking :D
I'm currently using it for a presentation script that compresses data via huffman coding, i will post my script as an example soon, but well, I don't know what other useful applications there may be. You can use it to implement any binary coding with fixed source words and code words ;)