# Converting Integer to any base

Discussion in 'Java' started by Dexter, Mar 20, 2008.

1. ### DexterGuest

Recently on a coding test , I was given a problem to write a program
that converts an integer to any given base between 2 and 16
(inclusive). I had written it in C# as this code is available to
viewers at

http://www.thinkanddone.com/prog/cs/integer2decimal.html

Hope it finds it use for someone facing the same problem

Dexter, Mar 20, 2008

2. ### Roedy GreenGuest

On Thu, 20 Mar 2008 01:11:58 -0700 (PDT), Dexter
<> wrote, quoted or indirectly quoted someone who
said :

>Recently on a coding test , I was given a problem to write a program
>that converts an integer to any given base between 2 and 16
>(inclusive). I had written it in C# as this code is available to
>viewers at

the code is built in to java. See
--

The Java Glossary
http://mindprod.com

Roedy Green, Mar 20, 2008

3. ### Lasse Reichstein NielsenGuest

Dexter <> writes:

> Recently on a coding test , I was given a problem to write a program
> that converts an integer to any given base between 2 and 16
> (inclusive).

....
> Hope it finds it use for someone facing the same problem

I would recommend anyone with the same problem to think it over
and find their own solution. And anyone who only needs to convery,
not write a program to convert, to use the one built into the
language. It was made by experts.

It can be done *much* shorter than what you have done.
<URL:http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Integer.html#toString(int, int)>

Example source here:
<URL:http://www.docjar.com/html/api/java/lang/Integer.java.html>

/L
--
Lasse Reichstein Nielsen -
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'

Lasse Reichstein Nielsen, Mar 20, 2008
4. ### DexterGuest

On Mar 20, 6:12 pm, Lasse Reichstein Nielsen <> wrote:
> Dexter <> writes:
> > Recently on a coding test , I was given a problem to write a program
> > that converts an integer to any given base between 2 and 16
> > (inclusive).

> ...
> > Hope it finds it use for someone facing the same problem

>
> I would recommend anyone with the same problem to think it over
> and find their own solution. And anyone who only needs to convery,
> not write a program to convert, to use the one built into the
> language. It was made by experts.
>
> It can be done *much* shorter than what you have done.
> <URL:http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Integer.html#toStri...., int)>
>
> Example source here:
> <URL:http://www.docjar.com/html/api/java/lang/Integer.java.html>
>
> /L
> --
> Lasse Reichstein Nielsen  -
>  DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
>   'Faith without judgement merely degrades the spirit divine.'

I am no expert.