3

How can I represent a real number using only 0's and 1's? I do not want to use any extra symbol like '.' to separate the integer part and the mantissa.

MatteoBianchetti
  • 436
  • 3
  • 10
  • You must used a fixed partitioning - A pre-specified number of bits for every part. (Along with a sign bit, that's actually how floating point numbers are represented) – Guest 86 Aug 24 '14 at 18:34
  • Actually fixed point numbers are also represented this way - Any number used by a computer has to be since there is ultimately nothing but 0s and 1s. – Guest 86 Aug 24 '14 at 18:36
  • 1
    Well there are various ways to do it. For example start by writing it in base 2. Let's say you get the number $101.001=a_3a_2a_1.b_1b_2b_3$. You can write this as $a_1b_1a_2b_2a_3b_3=100011$ – ThePortakal Aug 24 '14 at 18:40
  • @ThePortakal: your idea seems good. Thanks very much. – MatteoBianchetti Aug 24 '14 at 19:18

1 Answers1

3

Well, the function

$$f(x) = \frac{\arctan x + \pi/2}{\pi}$$

is a bijection from $\mathbb{R} \to (0,1)$. So when you take a number $x$ and compute $f(x)$, you obtain a number in the form of $0. [\dots]$; then any number may be represented only by the mantissa, since the integer part would be $0$ for all of them anyway, and since $f$ is a bijection, each mantissa uniquely identifies a real number.

Hence, you may just pick a random $x \in \mathbb{R}$, find its binary representation, and then use it to compute $f(x)$ in binary representation as well; the result will once again be a number whose integer part is $0$ as before, but this time the mantissa will only consist of $0$'s and $1$'s because of the binary representation; and for the reasons stated above, this mantissa can be the representation of $x$ you need for your purposes.

Labba
  • 1,001
  • 1
  • 7
  • 16
  • This answer is also good, even if I prefer to avoid the extra-step of squeezing \R onto (0,1). But it is a good idea too. Many thanks. – MatteoBianchetti Aug 24 '14 at 19:20