bcedfg interpreted as hex (base: 16 ). However, the hexadecimal scale collapses after f , so in javascript, g and everything after it is deleted before conversion. With that said here, how the conversion works:
decValueOfCharPosition = decValueOfChar * base ^ posFromTheRight
So:
b = 11 * 16^4 = 11 * 65536 = 720896 c = 12 * 16^3 = 12 * 4096 = 49152 d = 13 * 16^2 = 13 * 256 = 3328 e = 14 * 16^1 = 14 * 16 = 224 f = 15 * 16^0 = 15 * 1 = 15
Once you recognize the decimal value for each character position, just add them together to get the converted decimal value:
b(720896) + c(49152) + d(3328) + e(224) + f(15) = 773855
C, and this offspring is not so soft when it comes to typing. Instead of deleting the first invalid character and any characters that may follow it, C throws a Format Exception . To get around this, in order to get javascript functionality, you must first remove the invalid character and its subsequent ones, then you can use:
Convert.ToInt32(input, base)
I did not include a way to remove invalid characters due to the fact that there are several ways to make as such, and my sub-sub-C knowledge
source share