Charles Bell
Posts: 519
Nickname: charles
Registered: Feb, 2002
|
|
Re: Conversion from decimal to dotted decimal base 256 number
|
Posted: Apr 29, 2003 10:18 AM
|
|
It looks like you need to parse a String one character at a time and process.
This is only a guess at the conversion of your algorithm to java:
public int readValue(int base, String s){
boolean negative;
char ch;
int number = 0;
int index = 0;
do{
//read (ch)
ch = s.charAt(index++);
}while (ch <= ' ');
if (ch == '-'){
negative = true;
//read (ch)
ch = s.charAt(index++);
}else{
negative = false;
if (ch == '+') {
//read (ch)
ch = s.charAt(index++);
}
}
//while (value(ch),base){
while (index < s.length()){
//number = number * base + value(ch);
number = number * base + (int)ch;
//read (ch)
ch = s.charAt(index++);
}
if (negative) {
number = -number;
}
return number;
}
|
|