Pack()

From TinyMUX
Jump to navigation Jump to search

Description

FUNCTION: 20px-Function.png pack(number[,radix])

Returns the equivalent of the given number using the specified base. The default radix is 64. Bases greater than 10 will be more compact than the original number. Bases less than 10 will be more expanded.

The inverse function of pack() is unpack(). pack() and unpack() are designed to support the base-36 radix conversion used in Myrddin's popular Bulletin Board. For this reason, and to support bases: 2, 8, and 16, this conversion is not the radix-64 conversion used in unix-to-unix copy (uuencode).

Related Topics: unpack()

Examples

>think pack(629126998)
bVxTM
>think pack(629126998,16)
257FB756
>think pack(629126998,2)
100101011111111011011101010110
>think pack(-629126998)
-bVxTM
A common computer joke asks, "Why do programmers get Christmas and Halloween confused? Because DEC 25 equals OCT 31!" With pack() we can prove this by converting the DECIMAL number 25 to OCTAL (base 8) as follows:
> say pack(25, 8)
You say, "31"


(--Soylent 01:29, 3 December 2005 (EST))