Skip to content

Instantly share code, notes, and snippets.

@sanrodari
Forked from godie007/algo.java
Created June 1, 2012 21:09
Show Gist options
  • Save sanrodari/2855157 to your computer and use it in GitHub Desktop.
Save sanrodari/2855157 to your computer and use it in GitHub Desktop.
package Trabajo;
public class DecimalAOctal {
public static void main(String[] args) {
octalADecimal("765");
}
public static void octalADecimal(String base) {
String cadenaInver = "";
int b = 0;
int c = 0;
for (int i = base.length()-1; i >= 0; i--) {
cadenaInver += ""+base.charAt(i);
}
for (int i = 0; i <= cadenaInver.length(); i++) {
String convertir = "" + cadenaInver.charAt(i);
b = Integer.parseInt(convertir);
c += (b * Math.pow(8, i));
}
System.out.println(c);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment