Expand description
This crate adds a tool to format a number in an arbitrary base from 2 to 61.
This is a light crate, without any dependency.
For primitive signed integers (i8 to i128, and isize), negative values are formatted as the two’s complement representation.
§Get started
Add the crate in the cargo manifest:
radix_fmt_ng = "1"Import radix in scope, and you are ready to go:
use radix_fmt_ng::radix;§Examples
use radix_fmt_ng::*;
let n = 35;
// Ouput: "z"
println!("{}", radix(n, 36));§FAQ
- What if I want to use the capitalized letters as digits?
No. If you did that the conversion from 36 to 61 would be meaningless.
- Why does the formatting of negative numbers give a weird result?
Just as in the standard library, when a number is formatted in a non-decimal base, the two’s complement representation is used. That means that the number is casted to the unsigned version (for example, for an
i8the following number is used:n as u8).
Structs§
- Radix
- A struct to format a number in an arbitrary radix.
Functions§
- radix
- A helper for creating a new formatter from
Radix::new.