## digitalmars.D.learn - Convert number from one base to other

• ns (8/8) Jun 29 2007 Can some one please tell me if it is possible to convert a number from o...
• Stewart Gordon (9/12) Jun 29 2007 Yes. Any Turing complete language, of which D is an example, can be use...
• ns (3/19) Jun 29 2007 Thank you
ns <ns dummy.com> writes:
```Can some one please tell me if it is possible to convert a number from one
base to another arbitrary base. Is there any language construct or library
function ?

I know that it is easy to specify number literals in different bases like
0123
0x12

SK
```
Jun 29 2007
"Stewart Gordon" <smjg_1998 yahoo.com> writes:
```"ns" <ns dummy.com> wrote in message news:f639ka\$2nhc\$1 digitalmars.com...
Can some one please tell me if it is possible to convert a number from one
base to another arbitrary base.

Yes.  Any Turing complete language, of which D is an example, can be used to
implement an algorithm to do this.

Is there any language construct or library function ?

<snip>

std.string.toString(long value, uint radix) converts a number to any base
between 2 and 36.  There doesn't seem to be a function in Phobos to convert
_from_ an arbitrary base - don't ask me why.  But it shouldn't be difficult
to write a function to do this.

Stewart.
```
Jun 29 2007
ns <ns dummy.com> writes:
```Thank you
SK

Stewart Gordon wrote:
"ns" <ns dummy.com> wrote in message news:f639ka\$2nhc\$1 digitalmars.com...
Can some one please tell me if it is possible to convert a number from
one base to another arbitrary base.

Yes.  Any Turing complete language, of which D is an example, can be
used to implement an algorithm to do this.

Is there any language construct or library function ?

<snip>

std.string.toString(long value, uint radix) converts a number to any
base between 2 and 36.  There doesn't seem to be a function in Phobos to
convert _from_ an arbitrary base - don't ask me why.  But it shouldn't
be difficult to write a function to do this.

Stewart.

```
Jun 29 2007