Last active
December 14, 2015 21:08
-
-
Save machinamentum/5148682 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.UnsupportedEncodingException; | |
/** | |
* Converts a given String to base 26 then spits out its decimal equivalent. | |
* @author joshuahuelsman | |
*/ | |
public class StringToNumber { | |
public static void main(String[] args) throws UnsupportedEncodingException { | |
System.out.println(args[0]); | |
byte[] b = args[0].toUpperCase().getBytes("UTF-8"); | |
long number = 0; | |
for(int i = 0; i < b.length; i++) { | |
b[i] -= 'A'; | |
} | |
for(int i = b.length - 1; i >= 0; i--) { | |
number += b[i] * (Math.pow(26, (b.length - 1) - i)); | |
} | |
System.out.println(number); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment