![]() |
|
|
#2014 |
|
Aug 2006
3×1,993 Posts |
|
|
|
|
|
|
#2015 |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
I got it redefined without using b1digs or b2digs, it's still a incredibly slow script lol. Can't do convert(233,4,10) in under 4 minutes in the older version.
Last fiddled with by science_man_88 on 2010-12-05 at 16:22 |
|
|
|
|
|
#2016 |
|
"Forget I exist"
Jul 2009
Dumbassville
20C016 Posts |
Code:
(12:20)>convert(101,2,4) *** user interrupt after 12mn, 42,922 ms. okay it works well for some like: Code:
(13:06)>convert(11111,2,34) %150 = "v[]" (13:06)>## *** last result computed in 0 ms. I figured out why lol I forgot a statement of a=a\b2 in the until loop. now I find it doesn't work out properly. I figured out I changed a formula and forgot to change it back lol. Last fiddled with by science_man_88 on 2010-12-05 at 17:24 |
|
|
|
|
|
#2017 |
|
"Forget I exist"
Jul 2009
Dumbassville
26×131 Posts |
Well I now know why because a\b2 ==0 is wrong this is always fun. It should of been a/b2 not a\b2 I got it working now if only i can get rid of the [] in the answers. I did that stuff in my original code I do that and I have a converter that should work not only to binary but between any matchups from base 2 to 36. though I should add a check of that and if they are equal spit back the string at them lol.
Last fiddled with by science_man_88 on 2010-12-05 at 17:37 |
|
|
|
|
|
#2018 |
|
"Forget I exist"
Jul 2009
Dumbassville
26×131 Posts |
Code:
convert(numb1,b1,b2)={
my(B=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"],a=0,c="");
numb1=Vec(Str(numb1));
forstep(y=#numb1,1,-1,
for(x=0,b1,
if(numb1[y]==B[x],
a=a+(x-1)*b1^(#numb1-y)
)
)
);
until(a/b2==0,
c=concat(B[a%b2+1],c);
a=a\b2
);
c
};
this doesn't do better than binary for to base 2 conversion at least from base 36 lol. Last fiddled with by science_man_88 on 2010-12-05 at 21:07 |
|
|
|
|
|
#2019 | |
|
"Forget I exist"
Jul 2009
Dumbassville
26×131 Posts |
Quote:
|
|
|
|
|
|
|
#2020 |
|
Mar 2006
Germany
B5C16 Posts |
Another solution for this task:
Code:
\\ Convert number given in base1 into base2
convert(number,base1,base2)={
my(B=Vecsmall("0123456789abcdefghijklmnopqrstuvwxyz"),a=0,c="");
number=Vecsmall(number);
forstep(y=1,#number,1,
a*=base1;
a+=number[y]-48-(number[y]>=97)*39;
);
until(a/base2==0,
c=concat(Strchr(B[a%base2+1]),c);
a=a\base2;
);
c
};
Last fiddled with by kar_bon on 2010-12-06 at 01:53 |
|
|
|
|
|
#2021 | |
|
"Forget I exist"
Jul 2009
Dumbassville
20C016 Posts |
Quote:
Code:
(21:54)>convert1(1111111,2,10) %15 = "1111024" Last fiddled with by science_man_88 on 2010-12-06 at 02:07 |
|
|
|
|
|
|
#2022 | |
|
Mar 2006
Germany
22·727 Posts |
Quote:
<number> has to be given as a string! so convert1("1111111",2,10) will do the trick! Advantage: You can insert any 'number' in any base from 2 to 35 and convert in any of these bases. For example: convert1("1j3",20,10) gives "783" convert1("783",10,16) gives "30f" or in one step convert1("1j3",20,16) gives "30f" |
|
|
|
|
|
|
#2023 | |
|
"Forget I exist"
Jul 2009
Dumbassville
26·131 Posts |
Quote:
wonder how fast each is. tested both with the equivalent of 36^577-1 and they came up equal. Last fiddled with by science_man_88 on 2010-12-06 at 02:41 |
|
|
|
|
|
|
#2024 |
|
Aug 2006
597910 Posts |
|
|
|
|
![]() |
| Thread Tools | |
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Why do I sometimes see all the <> formatting commands when I quote or edit? | cheesehead | Forum Feedback | 3 | 2013-05-25 12:56 |
| Passing commands to PARI on Windows | James Heinrich | Software | 2 | 2012-05-13 19:19 |
| Ubiquity commands | Mini-Geek | Aliquot Sequences | 1 | 2009-09-22 19:33 |
| 64-bit Pari? | CRGreathouse | Software | 2 | 2009-03-13 04:22 |
| Are these commands correct? | jasong | Linux | 2 | 2007-10-18 23:40 |