Base 36 Conversions

 

Another conversion to GnuCOBOL of a set of functions I originally wrote in BASIC for an application where I had a lot of alternate keys being managed for a central dataset.  I needed to compact some large numbers into as small a storage unit as possible for inclusion in key fields.  The original was designed using Base 25, but everything has just gotten larger as time has passed, so I used the opportunity of this conversion to move up to Base 36.  Not a complex solution, but if it is of use to even one more individual, worth the effort to upload here.  I include a simple program to verify the routines are functioning correctly and to illustrate their use.

To install the source programs, and compile them, execute the bash script:  Base36setup [md5: 070fe8d77bd4831a867f11b76a3bb0af].  Right click and save the script in the location where you want the source program to reside, then execute it.  It will create two files containing the source programs, then execute the GnuCOBOL compiler to compile them into the run unit for the test program.  The GnuCOBOL compiler must be installed prior to executing the bash script.  

Output from the test/verification program:

jay@Phoenix $ ./t_base36
Test Value   >Base36  RC(1)   >Base10      RC(2)
0000000020   00000K   +0000   0000000020   +0000
0000000200   00005K   +0000   0000000200   +0000
0000000300   00008C   +0000   0000000300   +0000
0000003000   0002BC   +0000   0000003000   +0000
0000040000   000UV4   +0000   0000040000   +0000
0000050000   0012KW   +0000   0000050000   +0000
0000602350   00CWRY   +0000   0000602350   +0000
2176782335   ZZZZZZ   +0000   2176782335   +0000
2176782336   000000   +0008                     
5120000001   000000   +0008                     

If you want to be able to dynamically call the subprograms, separate the two programs contained in base36.cbl into their own file (toBase36.cbl and fromBase36.cbl), compile them into separate object modules (cobc -m toBase36.cbl fromBase36.cbl), and move the object modules (toBase36.so and fromBase36.so) to a location included in your COB_LIBRARY_PATH.


This page was last updated on May 24, 2016.