Binary

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
binary fractions work just like decimal fractions:

first digit = 1/2
second = 1/(2*2) = 1/4
thrid = 1/(2*2*2* = 1/8
. . . .
nth = 1/2^n

(ed) so 0.011 = 3/8 = 0.375
 

crazygal

Senior member
Feb 26, 2002
469
0
0
Thanks but I don't know which powers of 2 I need to make it -2/3.

In other words, what's an algorithm to find which powers of 2 make up a number less between 0 and 1?
 

crazygal

Senior member
Feb 26, 2002
469
0
0
That's what it's for. I carry it out to the 20th place. I found it equal to .10101010... just by taking 2/3 and subtracting various powers of 2 from it randomly but I can't use that method to find other fractions all the time.
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
Originally posted by: crazygal
That's what it's for. I carry it out to the 20th place. I found it equal to .10101010... just by taking 2/3 and subtracting various powers of 2 from it randomly but I can't use that method to find other fractions all the time.

Actually you can do it that way, more or less:

frac_unclaimed = frac
while (frac_unclaimedr > minimum_error)
{
if this power of 2 > frac_unclaimed
{
use this power of 2 and reduce frac_unclaimed
}
}

(ed) this works for any base, not just 2. I had to write import-export filters for SPSS once which uses base-36 :p