1
$\begingroup$

I follow a course in Computer Architecture and I'm making exercises on number conversions. Now one of the questions asks me to convert 251.5625 to octal and hexdecimal base. No further info is given. Would this mean that I have to convert it and just ignore the point? Or what's the convention on something like this?

$\endgroup$
  • $\begingroup$ Perhaps the question is a test of your understanding the different ways of representing fractional numbers in computer architecture. As there are many different ways of representing the numbers there would be many answers. If you have only been taught one representation, then surely the answer must use that. Look at your course notes. $\endgroup$ – Brian Tompsett - 汤莱恩 May 1 '16 at 11:10
  • $\begingroup$ Thank you! That's indeed a possibility. We've studied the fixed point and floating point notation. So I'll try both of them. $\endgroup$ – Pieter Verschaffelt May 1 '16 at 11:51
  • $\begingroup$ @BrianTompsett-汤莱恩 Actually, there is only one common interpretation of the representation of a given real number in a given base. $\endgroup$ – Yuval Filmus May 1 '16 at 16:39
1
$\begingroup$

Every non-negative real number can be represented in any integer base $b \geq 2$ as a string of the form $$ x_{n-1} \ldots x_0.x_{-1} x_{-2} \ldots, $$ where $x_i \in \{0,\ldots,b-1\}$, and the string is interpreted as having the value $$ x_{n-1} b^{n-1} + \cdots + x_0 b^0 + x_{-1} b^{-1} + x_{-2} b^{-2} + \cdots. $$ For example, 251.5625 in base 10 is the number $$ 2 \times 10^2 + 5 \times 10^1 + 1 \times 10^0 + 5 \times 10^{-1} + 6 \times 10^{-2} + 2 \times 10^{-3} + 5 \times 10^{-4}. $$ (You can extend this to negative numbers as well by allowing negation, e.g. -3.)

It is a basic result of arithmetic that every non-negative real number has a base $b$ expansion. In general, every number has infinitely many expansion: for example, 251.5625 can also be written as 0251.5625 or as 251.56250. If we don't allow leading and trailing zeroes then some numbers have a unique expansion, for example 0.33333…, and some numbers have two expansions, for example 251.5625 = 251.562499999….

A number is of the second form (has two expansions) if and only if it has a terminating expansion, that is one which is finite (for example 251.5625). The only number in base $b$ with this property are those of the form $N/b^k$ for integers $N,k \geq 0$. For example, 251.5625 = 2515625/104.

In your case, notice that 251.5625 = 4025/24. This shows that your number has a terminating expansion in any even basis, and in particular in base 8 (octal) and base 16 (hexadecimal). There are known algorithms to convert between bases, that you can find off the internet.

If you already know how to convert integers among bases, then you really also know how to convert non-integers, as long as they have a terminating expansion in the target base. To illustrate the method, consider the number 2.25. We want to convert it to base 4. Note that 2.25=9/4. Now 9 in base 4 is 214 (the subscript is how we indicate the base), and so 9/4 in base 4 is 2.14, since moving the decimal mark one digit to the left (from 21. to 2.1) is tantamount to dividing by the base (similarly, moving it to right corresponds to multiplying by the base).

Hopefully this theoretical information suffices for your problem.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.