tags:

views:

83

answers:

3

I want to create a program for generating the series for the given base-n. , for example if my input is 2,then series shuould be, 00,01,10,11,etc.,(binary) if my input is 10,then series shuould be,1,2,3,4,5,etc.,(decimal)

is there any general mechanism to find these numbers so that I can program for base-n.,

UPDATE:- After,working out.,i face issue.

If I want to process that integer how to do that? Some body commented that, BaseInteger class I should use. please elaborate

+10  A: 

You could use Integer's toString(int i, int radix) method for that.

For example:

Integer.toString(2, 2) // number 2, base 2

returns the string:

"10"

Note that the radix should be between 1 and 36.

Bart Kiers
+2  A: 

You might be looking for something like this (take a peek at "Algorithm: Constructing Base b Expansions"):

https://docs.google.com/viewer?url=http://websupport1.citytech.cuny.edu/faculty/dkahrobaei/Integers%2520and%2520Algorithms.pdf

David Soroko
BTW looking at the source of Integer.toString(int i, int radix) I see that it does pretty much the same thing.
David Soroko
+1  A: 

I think you should first figure in which format you need the results. If they should be Strings, Bart's answer would probably suit you. An integer representation, which does actually mean something else (e.g. the int 10 does mean 2 with base 2) seems awkward to me. If i would need something like you described, i would probably implement a BaseNumber class first.

Correct,I didnot think about it..If I want to process the integers then I must do as you said.Whether BaseNumber is an Java.lang class?
Senthil
i am not aware of a java.lang class, sorry.