CodeCamper
CodeCamper

Reputation: 6980

Integer Radix, what exactly does it mean?

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

Answers (1)

Jack
Jack

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

  • radix 2 - alphabet 0, 1 (binary number)
  • radix 8 - alphabet 0, 1, 2, 3, 4, 5, 6, 7 (octal number)
  • radix 10 - decimal number

and 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

Related Questions