Skip to main content

Discrete Mathematics for Computing (Draft)

Section 1.5 Converting Between Arbitrary Bases

Up to this point, we’ve discussed converting from base-\(b\) to base-\(10\) and also from base-\(10\) to base-\(b\text{.}\) We also discussed conversions between binary and either the octal or hexadecimal systems. We saw that this was made convenient because each group of three bits could be encoded as a single octal digit, and similarly each group of four bits could be encoded as a single hexadecimal digit. The relationship between the bases (\(8 = 2^3\) and \(16 = 2^4\)) is what made this possible. Such a quick conversion is not even possible between octal and hexadecimal because \(16\) is not a positive integer power of \(8\text{.}\)
Unfortunately, in order to convert between two arbitrary bases, we are stuck with converting to base-\(10\) and then from base-\(10\) into the desired new base. We’re already comfortable with each of these individual tasks, so rather than waste time with arbitrary base-conversions now, we’ll revisit this task later in our course. At that point, we’ll know a bit about logic and programmatic flow control, some looping structures, and we’ll tackle the problem with some code.