Finds the value in units of a number represented in a particular number system, for example, how many inches are in one yard. In general, the result is a scalar value generated from a vector representation of a value.
The left argument contains the base (or bases) of the number system being used. The right argument is a value represented in the given number system. A scalar left argument is treated as if it is a vector which matches the length of the right argument. Similarly, a scalar right argument is extended to match the length of the left argument.
To reduce the vector 3 2 6 9 representing, say, the readings of the separate dials on a meter, to a single number:
10 ⊥ 3 2 6 9 (10 is the base for the conversion) 3269
To convert a number represented in octal (base 8) to decimal:
8 ⊥ 3 1 (Note that as before, the right argument 25 is a vector)
To reduce 1 yard 2 feet 8 inches to inches:
1760 3 12 ⊥ 1 2 8 (12 is the base for converting feet to 68 inches, 3 is the base for converting yards to feet. For 1760 see the note below)
If both arguments to
2 2 2 ⊥ 1 (The 1 is extended to match the length of 7 the left argument)
To reduce 2 pounds 15 shillings 6 pence and 3 farthings to farthings (4 farthings to one penny, 12 pence one shilling, 20 shillings one pound):
0 20 12 4 ⊥ 2 15 6 3 2667
Again note the first number in the left-hand argument. Its only purpose is to make the arguments the same length.
The more general form of decode allows both left and right arguments to be numeric arrays. When the left argument is an array of rank 2 or more, it contains a set of vectors which describe different bases to be used independently. Each base lies along the last axis of the left argument, and is applied to each of the vectors on the first axis of the right argument.
To convert a matrix of yards, feet and inches to inches:
TABLE 1 1 1 (The numbers to be decoded lie along the 2 0 3 first axis, so the first value is 1 yard 0 1 8 2 feet 0 inches and so on)
1760 3 12 ⊥ TABLE (The left argument is applied to each 60 37 80 column of the right)
Copyright © 1996-2010 MicroAPL Ltd