1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
public class Number_Conversion_Rec { int dec2bin(int n, int c) //where starting value passed to c is 0 { if(n==0) //base condition return 0; int d = n%2; return (int)Math.pow(10, c)*d+dec2bin(n/2, c+1); } int bin2dec(int b, int c) //where starting value passed to c is 0 { if(b==0) //base condition return 0; int d = b%10; return (int)Math.pow(2, c)*d+bin2dec(b/10, c+1); } int dec2oct(int n, int c) //where starting value passed to c is 0 { if(n==0) //base condition return 0; int d = n%8; return (int)Math.pow(10, c)*d+dec2oct(n/8, c+1); } int oct2dec(int Oct, int c) //where starting value passed to c is 0 { if(Oct==0) //base condition return 0; int d = Oct%10; return (int)Math.pow(2, c)*d+oct2dec(Oct/10, c+1); } } |

## Leave a Reply

You must be logged in to post a comment.