Skip to main content

Module radix

Module radix 

Source
Expand description

Base conversion between integers and digit vectors (most significant first): BASE, and the 10-digit two’s complement of DEC2BIN / BIN2DEC and the rest of the radix 2 / 8 / 16 family.

Functions§

decode
The integer 10-digit two’s-complement digits ds in radix 2, 8 or 16 stand for (decode_spec): None for more than 10 digits or a digit not below r.
encode
v as 10-digit two’s complement in radix 2, 8 or 16: None exactly when v is outside [−r¹⁰/2, r¹⁰/2). The digits are those of v (v + r¹⁰ if negative) without leading zeros: at most 10, each below r, exactly 10 for a negative v, and decode maps them back to v.
round_trip
The round trip, as one statement: for every v in range, encode succeeds and decode of its digits gives v back.
to_digits
u in radix r (2…36): its digits, most significant first, without leading zeros (0 is one digit). Each digit is below r and they are worth exactly u.