# how to coonvert decimal number in tobase 64 format.

Discussion in 'Java' started by naveen, Aug 4, 2007.

1. ### naveenGuest

Hi friends,

My requirement is how to coonvert decimal number in
tobase 64 format.

the decimal number may be of type.

Example:
123,123.456,-123,-123.556

If any one knows any java API for this and how to use please send it
me.

Thanks,
Naveen

naveen, Aug 4, 2007

2. ### rossumGuest

On Fri, 03 Aug 2007 23:57:20 -0700, naveen <>
wrote:

>Hi friends,
>
> My requirement is how to coonvert decimal number in
>tobase 64 format.
>
>the decimal number may be of type.
>
>Example:
> 123,123.456,-123,-123.556
>
>If any one knows any java API for this and how to use please send it
>me.
>
>
>Thanks,
>Naveen

1 Look up how to convert integers from base 10 to binary, octal or
hexadecimal. Repeat the same process replacing 2, 8 or 16 with 64.
This works for both integers and the integer part of real numbers.

2 For the fractional part left once you have converted the integer
part just multiply repeatedly by your base and extract the whole
number part, which might be zero. The remaining fractional part is
cycled round again until either it goes to zero or repeats.

Example, 0.3 to binary fraction:

0.3 x 2 = 0.6 -> 0
0.6 x 2 = 1.2 -> 1
0.2 x 2 = 0.4 -> 0
0.4 x 2 = 0.8 -> 0
0.8 x 2 = 1.6 -> 1
etc.

0.3 decimal = 0.010011001(1001)... binary fraction

rossum

rossum, Aug 4, 2007

3. ### Roedy GreenGuest

Re: how to convert decimal number into base 64 format

>My requirement is how to convert a decimal number into
>base 64 format.

That question could have two meanings.
base64 is a common encoding.
You first have to convert to a byte array.
You would do that with Double.doubleToLongBits,
then break into bytes.
See http://mindprod.com/jgloss/base64.html
You might also mean base 64 in the sense of
binary, octal, hex, base 64.