Bug 13033 – std.conv.toBase too

Status
RESOLVED
Resolution
WONTFIX
Severity
enhancement
Priority
P1
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-07-03T17:12:00Z
Last change time
2016-12-23T19:56:34Z
Assigned to
nobody
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2014-07-03T17:12:02Z
In Phobos there is a function to convert from a string representing a number in any small base to an integral number: void main() { import std.stdio, std.conv; "00101201102".to!int(3).writeln; // Prints: 7814 } This is not supported: void main() { import std.stdio, std.conv; 101201102.to!int(3).writeln; } But it's easy to work around it: void main() { import std.stdio, std.conv; 101201102.text.to!int(3).writeln; // Prints: 7814 } But a rather common operation is to convert to arbitrary small base. I'd like a handy function like this in Phobos: void main() { import std.stdio, std.conv; 7814.toBase(3).writeln; // Should print: 101201102 }
Comment #1 by andrei — 2016-12-23T19:56:34Z
This seems too small and niche to warrant a special function.