Search All of the Math Forum:

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

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

 Messages: [ Previous | Next ]
 JT Posts: 1,448 Registered: 4/7/12
Re: JS coding
Posted: Feb 3, 2013 11:38 PM

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

> > In article

>
> >  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)
> > --

>
> (Sorry lines, were to long had to remove and repost)
> 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>

This is weird the code stop working after posting, why is there hidden
linebreaks or characters preventing JS?
I use just txt paste in and rename HTML so there should not be?

Date Subject Author
2/3/13 JT
2/3/13 JT
2/3/13 JT
2/3/13 Virgil
2/3/13 JT
2/3/13 JT
2/3/13 JT
2/3/13 JT
2/3/13 JT
2/4/13 JT
2/6/13 JT
2/6/13 Virgil
2/6/13 JT
2/7/13 JT
2/10/13 JT
2/10/13 Virgil
2/22/13 JT
2/23/13 Virgil
2/23/13 JT
2/23/13 JT
2/23/13 JT
2/24/13 JT
2/23/13 JT
2/6/13 JT
2/6/13 JT
2/6/13 JT
2/3/13 JT
2/3/13 JT