The OpenD Programming Language

toChars

Convert integer to a range of characters. Intended to be lightweight and fast.

pure nothrow @nogc @safe
toChars
(
ubyte radix = 10
Char = char
LetterCase letterCase = LetterCase.lower
T
)
()
if (
(
radix == 2 ||
radix == 8
||
radix == 10
||
radix == 16
)
&&
&&
(
radix == 10 ||
)
)

Parameters

radix

2, 8, 10, 16

Char

character type for output

letterCase

lower for deadbeef, upper for DEADBEEF

value T

integer to convert. Can be ubyte, ushort, uint or ulong. If radix is 10, can also be byte, short, int or long.

Return Value

Type: auto

Random access range with slicing and everything

Examples

import std.algorithm.comparison : equal;

assert(toChars(1).equal("1"));
assert(toChars(1_000_000).equal("1000000"));

assert(toChars!(2)(2U).equal("10"));
assert(toChars!(16)(255U).equal("ff"));
assert(toChars!(16, char, LetterCase.upper)(255U).equal("FF"));

Meta