gpBinEncode - General Purpose Binary Encoding

Post your working scripts, libraries and tools for AHK v1.1 and older
Alibaba
Posts: 480
Joined: 29 Sep 2013, 16:15
Location: Germany

gpBinEncode - General Purpose Binary Encoding

18 Aug 2015, 09:46

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
"Nothing is quieter than a loaded gun." - Heinrich Heine
Alibaba
Posts: 480
Joined: 29 Sep 2013, 16:15
Location: Germany

Re: gpBinEncode - General Purpose Binary Encoding

18 Aug 2015, 09:58

Oh btw, gpLoad/StoreBinString is BigEndian -> the byte with the msb is at the smallest adress
"Nothing is quieter than a loaded gun." - Heinrich Heine
Alibaba
Posts: 480
Joined: 29 Sep 2013, 16:15
Location: Germany

Re: gpBinEncode - General Purpose Binary Encoding

18 Aug 2015, 18:09

Update to v0.2:
-fixed approxAverageLength() function, that did something completely different than described in its documentation, sorry :D
"Nothing is quieter than a loaded gun." - Heinrich Heine
User avatar
BGM
Posts: 507
Joined: 20 Nov 2013, 20:56
Contact:

Re: gpBinEncode - General Purpose Binary Encoding

19 Aug 2015, 22:36

Ali, pardon me for asking, but what would you use this for? Onoce or twice in some math operations dis I use bitshifting.
Alibaba
Posts: 480
Joined: 29 Sep 2013, 16:15
Location: Germany

Re: gpBinEncode - General Purpose Binary Encoding

20 Aug 2015, 16:33

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 ;)
"Nothing is quieter than a loaded gun." - Heinrich Heine

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 206 guests