-1

Example

FC12 should be converted to a number say X

so that same X can again be convertible to FC12

Not Working

public int toInt(String s) {
    char ch[] = s.toCharArray();
    int value=0;
    int mult = 1;
    for (int i=0; i<ch.length; i++){
        value = value + ch[i] * mult;
        mult *= 100;
    }
    return value;
}

public String toStr(int value) {
    String s = "";
    while (value > 0) {
        s += (char)(value % 100);
        value = value / 100;
    }
    return s;
}
Bram Luyten
  • 1,034
  • 7
  • 18

1 Answers1

0

you need to use a factor of 1000(instead of 100), since some if the char codes are higher then 100 , for example (int) 'h' = 104

ShayM
  • 106
  • 5