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

Topic: JS coding
Replies: 27   Last Post: Feb 24, 2013 6:17 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
JT

Posts: 1,170
Registered: 4/7/12
Re: JS coding
Posted: Feb 3, 2013 11:30 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On 4 Feb, 05:24, JT <jonas.thornv...@gmail.com> wrote:
> On 3 Feb, 23:33, Virgil <vir...@ligriv.com> wrote:
>
>
>
>
>
>
>
>
>

> > In article
> > <6e315bac-9f19-4cee-ad90-7ec7bbe8b...@w7g2000yqo.googlegroups.com>,

>
> >  JT <jonas.thornv...@gmail.com> wrote:
> > > I do not want a counter, i want a general solution to re encode any
> > > decimal number where anybase(decimal,base) {}
> > > This is probably why people save code instead of posting it to
> > > usenet ;D

>
> > The process involves repeated divisions with whole number quotients and
> > remainder
> >  Example: Convert 99 base 10 to base 8

>
> > Step 1.  8 into 99 goes 12 times with 3 left over
> > Step 2.  8 into 12 goes 1  time  with 4 left over
> > Step 3.  8 into  1 goes 0  times with 1 left over
> > Stop when base goes into dividend 0 times

>
> > Then line up the leftovers from last to first: 1,4,3
>
> > Result 99(base 10) is 143(base 8)
>
> > Check: 143(base 8) = 1*8^2 + 4*8^1 + 3*8^0
> >                    = 1*64  + 4*8   + 3*1
> >                    =   64  + 32    + 3
> >                    =   99  (base 10)
> > --

>
> Thank you for helping out, but that is not the formula i am looking
> for see the serie above.
> Your idea use the formula creating standard base including zero.
>
> I ask for the general formula writing out the multiples without zeros.
> I do not want base 3 (normal way)
>      9=100=1*9 + 0*3 + 0*1
> (I already have a general formula for anybase, see the javascript)
>
> I want base 3 (doing my way)
>       9=23=2*3 + 1*3
>
> From script i want 2,3 out not 1,0,0
> But i forgot how to change it to reflect my serie writing bases
> without zeros.
>
> But if you or anyone else could figure out howto change code to
> reflect the zeroless serie above, i would be greatful, right now i am
> lost.
> And if you find a way to improve code to make it readable (normal
> bases)please do so, this is in no way optimal just my hack.
> (Below you have boiled down code for basechange (works for all bases
> and numbers) just put your base and decimal number in function call.
>
> Thanks Virgil
>
> <HTML>
> <SCRIPT language=Javascript>
> function anybase(bas,decimal) {
>
> multip=0;
> basemultip=1;
> unr=0;
> basestr="";
> subtrahend=0;
>
> while (basemultip<decimal){
>  basemultip=basemultip*bas;
>   multip=multip+1;
>  }
> while (decimal>0){
>      unr++;
>      set=0;
>
>          for(i=bas;i>0;i--){
>               subtrahend=basemultip*i;
>               document.write(subtrahend+"="+basemultip+"* (i)"+i
> +"<BR>");
>
>              if (decimal>=subtrahend) {
>                  document.write("decimal"+decimal+"-
> subtra"+subtrahend);
>                  decimal=decimal-subtrahend;
>                  document.write("="+decimal+"<BR>")
>                  set=1;
>                  basestr=basestr+i+",";
>
>              }
>
>         }
>
>         if(set==0 && decimal!=0)basestr=basestr+0+",";
>         basemultip=basemultip/bas;
>
> }
>
> while (multip>=unr){
>        basestr=basestr+0+",";
>        unr++;
>
>   }
>    document.write("basestr "+basestr+"<BR>");
>
> }
>
> anybase(4,81);
> </SCRIPT>
> <HTML>


I have no idea after copying code from NG it do not work, strange.
Test again.
<HTML>
<SCRIPT language=Javascript>
function anybase(bas,decimal) {

multip=0;
basemultip=1;
unr=0;
basestr="";
subtrahend=0;

while (basemultip<decimal){
basemultip=basemultip*bas;
multip=multip+1;
}
while (decimal>0){
unr++;
set=0;

for(i=bas;i>0;i--){
subtrahend=basemultip*i;
document.write(subtrahend+"="+basemultip+"* (i)"+i
+"<BR>");

if (decimal>=subtrahend) {
document.write("decimal"+decimal+"-
subtra"+subtrahend);
decimal=decimal-subtrahend;
document.write("="+decimal+"<BR>")
set=1;
basestr=basestr+i+",";

}




}

if(set==0 && decimal!=0)basestr=basestr+0+",";
basemultip=basemultip/bas;

}
while (multip>=unr){
basestr=basestr+0+",";
unr++;

}
document.write("basestr "+basestr+"<BR>");

}
anybase(4,81);
</SCRIPT>
<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.