NAME

encode - compute the representation of the argument in the radix system defined by the base

SYNOPSIS

val0.encode(val1)

DESCRIPTION

The decode method is similar to the APL ⊤ operator. It can be used to convert an integer to a sequence of digits in an arbitrary base. It can be used to implement a "divmod" function. And it can be used to convert, for example, seconds to hours/minutes/seconds in one step.

val0 and val1 can be an arbitrary multidmensional numeric arrays. Note that the first element of the first dimension of the val0 vector is ignored - it is just there to provide the number of digits which should be computed.

The encode method is conceptually the inverse of the decode method.

RETURN VALUE

The encoded value or values

EXAMPLE

    // Convert number of seconds to days, hours, minutes, seconds
    [0,7,24,60].encode(12345)
1 1 13 45

    // 121 in binary, decimal, and hexadecimal, with at most 8 digits
    // 1111011 binary, 121 decimal, 79 hexadecimal
    [2,10,16].reshape(8,3).encode(121)
0 0 0
1 0 0
1 0 0
1 0 0
1 0 0
0 1 0
0 2 7
1 1 9

    // Using encode for "divmod"
    [0,7].encode(123)
17 4

    ([17,4]*[7,1]).reduce(`+)
123

SEE ALSO

decode