IBM PureData System for Analytics, Version 7.1

The uuencode() function

The uuencode() function encodes a binary value as ASCII by using the UNIX UUencode format.

The encoding translates the binary value into ASCII character codes in the range 32 and above. Historically, uuencoding is used to encode files destined for email transmission. The uudecode() function reverses the effect of uuencode(), re-creating the original binary file exactly.

The uuencode() algorithm does the following tasks:
  1. Divides the binary value into groups of three bytes (24 bits), adding zeros to the end of the binary value if necessary to create a final group of three bytes.
  2. Splits the 24 bits into four groups of six bits each. This creates four decimal numbers in the range 0 - 63.
  3. Adds decimal 32 to each number to create ASCII characters in the range 32 (space) to 95 (underscore).
Step 1 is illustrated by the following table that shows how each character of an input value "hat" is processed into bytes.
Table 1. Uuencoding, Part I
Value type Input character Input character Input character
Original ASCII Input h a t
ASCII Decimal 104 97 116
ASCII Binary (8 bit) 01101000 01100001 01110100

Steps 2 and 3 are illustrated by the following table. The transformation of the three 8 bit ASCII Binary values in the preceding table to the four 6 bit Binary values in the first line of the table:

Table 2. Uuencoding, Part II
Value type Input value Input value Input value Input value
6 Bit Binary 011010 000110 000101 110100
Decimal Equivalent 26 6 5 52
Decimal + 32 58 38 37 84
Uuencoding : & % T

Description

The uuencode function has the following syntax:
varchar = uuencode(varchar input);
nvarchar = uuencode(nvarchar input);

The input value specifies the binary value to be uuencoded.

Returns

The function returns a UUencoded string. For example:
select uuencode ('hat');
      UUENCODE
--------------------
 begin
#:&%T
'
end

(1 row)

For uuencode() and uudecode(), the begin/end header information is important. If the header information is removed from the output of uuencode() and the encoded string is passed to uudecode(), the uudecode() function returns “ERROR: 0 : Invalid UUData”.



Feedback | Copyright IBM Corporation 2014 | Last updated: 2014-02-28