Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » sci.math.* » sci.math.independent

Topic: Is this correct way to describe fractions(decimals) in different bases?
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
JT

Posts: 1,041
Registered: 4/7/12
Is this correct way to describe fractions(decimals) in different bases?
Posted: Jan 31, 2013 10:58 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

Copy to textfile with extension HTML and run by doubleclick.


<HTML><HEAD><TITLE>TEST</TITLE>
<META http-equiv=Content-Type content="text/html;
charset=windows-1252">
<SCRIPT language=Javascript>
function anybase() {

fullnumber=document.doit.dnumb.value;
twoparts = fullnumber.split(",");
bas=document.doit.bval.value;


for(j=0;j<2;j++){
btwo=1;
bnr=0;
unr=0;

decimalnumber=twoparts[j];

while (btwo<decimalnumber){
btwo=btwo*bas;
bnr++
}
basestring="";
while (decimalnumber>0){
unr++;
set=0;
for(i=bas;i>0;i--){
st=btwo*i;
if (decimalnumber>=st) {
decimalnumber=decimalnumber-st;
set=1;
basestring=basestring+i+",";
}
}
if(set==0 && decimalnumber!=0)basestring=basestring+0+",";
btwo=btwo/bas;
}
while (bnr>=unr){
basestring=basestring+0+",";
unr++;
}
if (j==0) {radixout=basestring;document.doit.radix.value=radixout;}
if (j==1) {radixout=basestring;document.doit.fracted.value=radixout;}
}




control=document.doit.radix.value;
controldec=document.doit.fracted.value;
show=document.doit.dnumb.value+"=";
//Control Radix by go back to decimal
darr = control.split(",");
decarr = controldec.split(",");
darr.reverse();
decarr.reverse();

total=0;
totalfrac=0;
multiple=1
for (i=1;i<darr.length;i++){
cval=darr[i];
cval=cval*multiple;
total=total+cval;
show=show+"("+multiple+"*"+darr[i]+")+";
multiple=bas*multiple;
}


multiple=1
for (i=1;i<decarr.length;i++){
cval=decarr[i];
cval=cval*multiple;
totalfrac=totalfrac+cval;
show=show+"("+multiple+"*"+decarr[i]+")+";
multiple=bas*multiple;
}
totalfull=total+","+totalfrac;
document.doit.controlout.value=totalfull;
document.doit.overview.value=show;
}

</SCRIPT>
<HTML><BODY>
<FORM NAME=doit onSubmit="anybase(); return false;">
CHANGE BASE:
<input type=submit value="GO!"><P>
DECIMAL VALUE:<TEXTAREA NAME=dnumb COLS=30
ROWS=1>777777777777,3333333</TEXTAREA><BR>
BASE:<TEXTAREA NAME=bval COLS=30
ROWS=1>333</TEXTAREA><BR>
RADIX OUT:<TEXTAREA NAME=radix COLS=200
ROWS=1></TEXTAREA><BR>
FRACTION OUT:<TEXTAREA NAME=fracted COLS=200
ROWS=1></TEXTAREA><BR>

BACK TO DECIMAL CONTROL CONVERSION->
<TEXTAREA NAME=controlout COLS=30
ROWS=1></TEXTAREA><BR>
Radix HOWTO EXPLAIN<TEXTAREA NAME=overview COLS=200
ROWS=1></TEXTAREA><BR>

</FORM>
</BODY>
</HTML>



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.