### conversion

I have written program to do conversion between decimal to any base between 2 to 26..
but I cant handle alphabets as alphabets are also included in this conversion.

plz help..
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354`` ``````#include #include void conversion(int no,int base) { int arr[10]={0}; int i=0; while(no>0) { arr[i]=no%base; i++; no=no/base; } for(int j=i;j>=0;j--) cout<0) { arr[i]=no%base; i++; no=no/base; if(no>=10) { j=no%base; for(int k=0;k=0;l--) cout<=2 && base<=9) conversion(no,base); else if(base >=11 && base<=26) conversionGreater(no,base); getch(); }``````
There's no difference between the two cases.

Make the following string:

"0123456789abcdef....z" (actually this gives you up to base 36).

After you do the % to get the "digit", use the computed value to index into the string to find its character representation.

You can actually use this same technique to further generalize your program to handle allowing the user to input a number in any base and convert to any other base.

can you explain it
what you have said I do not understand it:(
In your conversion function, for example, you do a modulo (%).
The result of the modulo is the converted "digit" which is obviously a number.

In your conversionGreater function, as you point out, sometimes the modulo returns a number > 9, which you correctly recognize as being a letter, not a number. But you have an array of ints, and you can't really store letters there.

So what I'm saying is to change your array of ints to an array of chars.
Make the string I mentioned above. Now the [0]th index into the string is the character '0', the [1]st index is '1', and so forth. The [10]th index is 'a', which is the character that you want to print if the result of the modulo is 10.

So each time you perform the modulo, you'll get a number between 0 and (base-1). Use that number to index into the string to find the character you need to print.
check this function
 ``1234567891011121314151617`` ``````void conversionGreater(int no,int base) { int arr[20]={0}; char a[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int no1=0; while(no>0) { no1=no%base; cout<=10) { cout<
Topic archived. No new replies allowed.