![]() |
![]() |
|
home—info—lectures—exams—archive
---------- arithmetic: What does a numeral mean? stoi10 stoi2 itos10() itos2()
public static int stoi( String numeral, short base ) { int numSoFar = 0; int columnWeight = 1; // Start at 1's column, then 10s,100s,... (if base==10) for (int i=0; i < numeral.length(); ++i ) { numSoFar += dtoi( numeral.charAt( numeral.length()-1-i ) ) * columnWeight; columnWeight *= base; } return numSoFar; } public static String itos( int n, short base ) { String numeralSoFar = ""; int num = n; while (num > 0) { numeralSoFar = itod((short)(num % base)) + numeralSoFar; num /= base; } return numeralSoFar.isEmpty() ? "0" : numeralSoFar; } |
home—info—lectures—exams—archive
©2008, Ian Barland, Radford University Last modified 2008.Nov.17 (Mon) |
Please mail any suggestions (incl. typos, broken links) to ibarland ![]() |
![]() |