Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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

for example 64's equivalent would be 0.5

share|improve this question
    
$0.1 \cdot (127 / 10) = 1.27 > 1$. –  cardinal Apr 17 '11 at 2:18
    
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). –  cardinal Apr 17 '11 at 2:20

2 Answers 2

up vote 6 down vote accepted

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}.$

share|improve this answer

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}$.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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