4
$\begingroup$

How can represent any number from 0 to 127 as something between 0 and 1 ?

for example 64's equivalent would be 0.5

  • 0
    Just divide by 128. This is equivalent to using a seven-bit binary representation and placing the decimal point out front. So, for example, 64 in binary is 1000000 and $0.1000000$ in binary is 0.5 (decimal).2011-04-17

2 Answers 2

6

Lets look at numbers 1 to 128 rather than 0 to 127 because 0 to 127 can get confusing and the same formula will work for 0 to 127. We want to scale, or divide, each number by something so that the largest number is 1 and the smallest number is something greater than zero. So lets look at our first idea.

Call this number we want to divide by $x.$ Because we want our largest number, 128, to be equivalent to 1, we should get something like this: $\frac{128}{x}=1.$ Bring the $x$ to the other side and we will get $x=128.$

So every number can be converted to a ''float'' by $\frac{number}{128}.$

2

You could separate the segment between $0$ and $1$ into $128$ pieces, and from there on map $x$ (where $x\in \begin{Bmatrix} 0, & 1, & \dots, & 127 \end{Bmatrix}$) to $x \times \frac{1}{127}$.