This is a blast from my COBOL past.

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


In reply to Re: EBCDIC & COMP-3 *shriek* by Old_Gray_Bear
in thread EBCDIC & COMP-3 *shriek* by Grygonos

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.