I do not understand how in this example the number is translated. That is, I do not understand the last step ... From the line we take the character, then we calculate its index, accordingly we change the letters from the 16-system to numbers, and then ... How then? Everything works correctly, I checked (compiled), but if I sit on a piece of paper and I think it doesn’t work out for me at all, as the program comes to the right decision ... Maybe someone will step by step expand as correctly as the last. string when calculating val variable.
public static int hex2decimal(String s) { String digits = "0123456789ABCDEF"; s = s.toUpperCase(); int val = 0; for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); int d = digits.indexOf(c); val = 16*val + d; } return val; }