Advertisement
Guill

Last Update

Aug 19th, 2013
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.26 KB | None | 0 0
  1. package javaapplication3;
  2.  
  3. public class JavaApplication3 {
  4.  
  5.     public static void main(String[] args) {
  6.    //     dectobin(args,2036);
  7.    //     bintodec(args, "1111");
  8.    //     octtodec(args, "10021");
  9.    //     dectooct(args, 4113);
  10.    //     dectohex(args, 9889);    
  11.     }
  12.    
  13.     public static void JavaApplication3() {
  14.  
  15.     }
  16.    
  17.     static void octtodec(String[] args, String a){
  18.         if(a.contains("8") || a.contains("9")){
  19.             return;
  20.         }
  21.         int[] tab = new int[255];
  22.         int i = 0;
  23.         while(i <= a.length() - 1){
  24.             tab[i] = (int) Math.pow(8,i);
  25.             p(tab[i]);
  26.             i = i + 1;
  27.         }
  28.         int r = 0;
  29.         i = 0;
  30.         int l = a.length() - 1;
  31.         while(i <= a.length() - 1){
  32.             r = r + (Integer.valueOf(String.valueOf(a.charAt(i))) * tab[l]);
  33.             l = l - 1;
  34.             i = i + 1;
  35.         }
  36.         p("\n" + r);
  37.       /*  while(i > 0){
  38.             i = i - 1;
  39.             if(a >= tab[i]){
  40.                 r =  r + "1";
  41.                 a = a - tab[i];
  42.             }
  43.             else
  44.             {
  45.                 r = r + "0";
  46.             }
  47.         }
  48.         p("\n" + r); */
  49.     }
  50.    
  51.    
  52.     public static String hexe(Integer n){
  53.         String a = Integer.toString(n);
  54.         if(n > 15 || n < 10){
  55.             return a;
  56.         }
  57.         switch(n){
  58.             case 10: return "A";
  59.             case 11: return "B";
  60.             case 12: return "C";
  61.             case 13: return "D";
  62.             case 14: return "E";
  63.             case 15: return "F";
  64.         }      
  65.     }            
  66.    
  67.     static void dectohex(String[] args, Integer a){
  68.         String r = "";
  69.         while(a > 0){
  70.             r = hexe(a % 16) + r;
  71.             a = a / 16;
  72.             p(a + "\n");
  73.         }
  74.         p("\n" + r);
  75.     }
  76.    
  77.    
  78.     static void dectooct(String[] args, Integer a){
  79.         String r = "";
  80.         while(a > 0){
  81.             r = Integer.toString(a % 8) + r;
  82.             a = a / 8;
  83.             p(a + "\n");
  84.         }
  85.         p("\n" + r);
  86.     }
  87.    
  88.    
  89.    
  90.    
  91.    
  92.     static void dectobin(String[] args, Integer a){
  93.         int[] tab = new int[255];
  94.         int i = 0;
  95.         while(Math.pow(2,i) <= a){
  96.             tab[i] = (int) Math.pow(2,i);
  97.             p(tab[i]);
  98.             i = i + 1;
  99.         }
  100.         String r = "";
  101.         while(i > 0){
  102.             i = i - 1;
  103.             if(a >= tab[i]){
  104.                 r =  r + "1";
  105.                 a = a - tab[i];
  106.             }
  107.             else
  108.             {
  109.                 r = r + "0";
  110.             }
  111.         }
  112.         p("\n" + r);
  113.     }
  114.      
  115.     static void bintodec(String[] args, String a){
  116.         int[] tab = new int[255];
  117.         int i = a.length() - 1;        
  118.         while(i >= 0){
  119.             tab[i] = (int) Math.pow(2,i);
  120.             p(tab[i]);
  121.             i = i - 1;
  122.         }
  123.         i = a.length() - 1;
  124.         int r = 0;
  125.         int l = 0;
  126.         while(i >= 0){
  127.             r = r + (Integer.valueOf(String.valueOf(a.charAt(i))) * tab[l]);                  
  128.             l = l + 1;
  129.             i = i - 1;
  130.         }
  131.         p("\n" + Integer.toString(r));
  132.     }
  133.      
  134.     static void p(Object stri){
  135.         System.out.print(stri);
  136.     }
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement