in reply to EBCDIC & COMP-3 *shriek*
Comp-3 (aka 'packed decimal') is a compression technique for numbers on the IBM mainframes. In EBCDIC, the digits are x'F0', x'F1', etc. (Called 'zoned decimal' or display.) It was noted very early on (late 50's? certainly by the early 60's when OS/360 came out) that the string representation of digits containd a lot of redundant bits, from a computational point of view. You could compress out the 'noise' and reduce the memory foot print. COMP-3 was the COBOL name for this compressed form.
For example -- '1234' is x'F1F2F3F4' as a string, of length four bytes. The packed decimal representation is x'0123C4', only three bytes long; net saving 1 byte of memory and disk storage. Not so much, you say, but remember -- this technique was developed at the time when 24K of main memory was the norm. (That 'K' was not a typo. The first 'production' machine I wrote code for had 4096 bytes of memory!) Packed decimal will always be no longer than (length of source/2)+1, and could provide a considerable space savings for commercial programs. Scientific programming used floating point (either 32, 64, or 128 bits wide) and didn't concern itself with such trivia as memory footprint.
The process is to strip out the high order four bits of each number, concatenate all but the last digit together, insert a 'zone' to indicate the sign (odd zones (A, C, E) are positive; evens (B, D) are negative; if memory serves me. My green card is at home in the memorabilia drawer), followed by the last digit. If you started with an even number of digits in your string, you add a leading byte of zeros to make up a full byte. There are a full set of instructions that manage and compute with packed decimal format (including my favorite: Zero and ADD, Packed -- ZAP).
That out of the way, I suspect that a modicum of C<pack> and C<unpack> logic will get you where you want to go.
Best of luck,
----
I Go Back to Sleep, Now.
OGB
|
|---|