public class Decimaltonbigit {/** * decimal number (can be negative) to N (n between [2,36]) * @author wl */public static final int n=36;//n represents N binary public static void Main (string[] args) {int Data=71;//data represents the number of Tonbigit (data,n) to convert;} private static void Tonbigit (int data, int a) {if (a>36| | A<2) {System.out.println ("This binary is not supported!!! "); return;} if (data<0) {data= (( -1*data) ^ ((1<<31)-1)) +1;//turns negative numbers to positive numbers, then negation (^ ((1<<31)-1) is reversed) and finally 1;}int n= (data%a); int m= (data/a); if (m==0) {printnbigitnum (n);} Else{tonbigit (m,a);p rintnbigitnum (n);}} private static void Printnbigitnum (int n) {if (n>9&&n<=36) {System.out.print ((char) ((n-10) +65));} else if (n>36) {System.out.println ("This binary is not supported!!! "); return;} Else{system.out.print (n);}}
Output:
1Z
Java decimal number (supports negative numbers) to n binary (n between [2,36])