Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Convert decimal to fraction
Message
 
To
10/02/2003 19:14:34
Fabian Belo
Independent Developer
Argentina
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00751688
Message ID:
00752450
Views:
20
********************************************
* Convert a decimal part of a number
* in negative powers of 2
*****************************************************************************
**ip is the power of 2 (i.e. 1->2 / 2->4 / 3->8 / 4->16 / 5->32 / 6->64 )
*****************************************************************************
ip = 6 && (##) you can replace this line with : FOR ip = 1 TO 6
FOR j = 1 TO 2**ip-1 && to generate all different numbers
lcResu=2**ip
R=INT((j/lcResu-INT(j/lcResu))*lcResu) && just saves ip bits
R2=R
****************
FOR i = 1 TO ip
IF BITTEST(R, i-1) && consider a number as a multiple
&& of the ip power of 2
&& if its ip rightmost bits are all zero.
?TRANSFORM(j, '99')+"/"+TRANSFORM(2**ip, '99')+IIF(j=R2,""," => "+TRANSFORM(R2, '99')+"/"+TRANSFORM(lcResu, '99'))
EXIT
ELSE
R2=R2/2
lcResu=lcResu/2
ENDIF
ENDFOR
****************
ENDFOR
?"----------------------"
** (##) && you should replace it with : ENDFOR
*****************************************************************************
Previous
Reply
Map
View

Click here to load this message in the networking platform