Dev Helpers

JavaScript / Algorithms and collections

Convert a number to another radix

Dev Helpers · September 10, 2025

A radix changes how an integer is written. The numeric value stays the same while its string representation changes.

Worked example

console.log((255).toString(16), Number.parseInt("ff", 16));

Result

ff 255

Implementation notes

Radix conversion does not pad values for fixed-width storage. For a colour channel such as hexadecimal 0f, decide width and casing after conversion.

Try it yourself

Convert 31 to base two and base sixteen, then parse each with the matching radix.

Open the JavaScript example →

Editorial date September 10, 2025 · Published December 6, 2026

Related articles

Sum distances with a Euclidean norm

A diagonal is longer than either of its components. Math.hypot combines perpendicular distances without making the caller square each input.

Build an OS-independent path

Path conventions belong to the destination. Use an explicit path flavour when generating portable asset names.

Resolve ranked ties

A leaderboard needs an explicit tie policy. Ranking tied scores and sorting their display order are separate decisions.