⊤ — Encode

Keys: Alt-n. Ranks: ∞ monadic, 1 0 dyadic

⊤Y encodes nonnegative integers in binary, choosing enough digits for the largest value. Each number’s digits lie along a new last axis. Zero needs zero digits.

⊤5                ⍝ 1 0 1
⊤[2 5]ₓ           ⍝ [0 1 0⋄1 0 1]ₓ

B⊤Y represents numbers in bases B. A zero base retains the remaining quotient.

2 2 2 2⊤10         ⍝ 1 0 1 0
[0 60 60]ₓ⊤3661ₓ   ⍝ [1 1 1]ₓ

A unit B gives residues. A vector B adds a new last axis of digits. The result’s shape is ⍴Y , ⍴B. Exact operands retain exact arithmetic.

9⊤15               ⍝ 6
9⊤⊂15              ⍝ ⊂6
10⊤12 34           ⍝ 2 4
2 2 2⊤3 5          ⍝ [0 1 1⋄1 0 1]

See Decode.

Inverse

⊤⁻¹ is ⊥.

⊤⁻¹1 0 1       ⍝ 5
24 60⊤⁻¹1 30   ⍝ 90