File packunpk.icn

Summary

###########################################################################

	File:     packunpk.icn

	Subject:  Procedures to pack and unpack decimal strings

	Author:   C. Tenaglia (modified by Richard L. Goerwitz)

	Date:     May 2, 2001

###########################################################################

   This file is in the public domain.

###########################################################################

	Version:  1.2

###########################################################################

      Integers written directly as strings occupy much more space
  than they need to.  One easy way to shrink them a bit is to "pack"
  them, i.e.  convert each decimal digit into a four-byte binary
  code, and pack these four-bit chunks into eight-bit characters,
  which can be written to a file.

      Interestingly, packing decimal strings in this manner lends
  itself to unpacking by treating each character as a base-10
  integer, and then converting it to base-16.  Say we have an input
  string "99."  Pack() would convert it to an internal representation
  of char(16*9 + 9), i.e. char(153).  Unpack would treat this
  char(153) representation as a base-10 integer, and convert it to
  base 16 (i.e. 10r153 -> 16r99).  The 99 is, of course, what we
  started with.

      Note that two unpack routines are provided here:  The first, by
  Tanaglia, utilizes convert.icn from the IPL.  The second, by
  Goerwitz, does not.  They utilize very different methods, but both
  amount to basically the same thing.  Goerwitz's routine returns an
  integer, though, and has no "width" argument.

###########################################################################

  Links:  convert

###########################################################################
Procedures:
pack, unpack, unpack2

Links:
convert.icn

This file is part of the (main) package.

Source code.

Details
Procedures:

pack(num, width)


unpack(val, width)


unpack2(val)



This page produced by UniDoc on 2021/04/15 @ 23:59:54.