Reputation: 6980
Integer.valueOf("10", 2)
what should this return and why? I thought a radix was the base of a number but I am confused as to what this function is doing exactly with different values.
Upvotes: 1
Views: 5997
Reputation: 133587
Every number representation requires to know the radix or base to be converted to a real value.
The radix identifies the "alphabet" of the digits like you thought. Indeed you could have
2
- alphabet 0, 1
(binary number)8
- alphabet 0, 1, 2, 3, 4, 5, 6, 7
(octal number)10
- decimal numberand so on. But nothing prevents you from having a "radix-9" number with an alphabet of 0..8
so that 381
would be 3*radix^2 + 8*radix^1 + 1*radix^0
.
Upvotes: 4