Many times when you wish to bash a problem with 'programmingbash', changing base of a number is needed. Of course we can use wolfram, but it'll get irritating if there are too many numbers.
So here, $\color{#3D99F6}{\text{Python comes to our help!}}$
I've written this program in Python 2.7, for getting a decimal number in some other base...
($\text{cb}$ stands for change_base )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 

First I had written that using the while
loop for $n$, got pretty bad...
It left zeroes that come in between, and also I couldn't efficiently assign Alphabets to digits greater than 9.
But now, I've made it shorter and efficient with the while
loop for $y$.
Here's the program for the other way, changing a number from other way, into decimal!
1 2 3 4 5 6 7 8 9 10 11 12 

I want to know if there are any improvements that you can spot, thanks!
$</code> ... <code>$</code>...<code>."> Easy Math Editor
*italics*
or_italics_
**bold**
or__bold__
paragraph 1
paragraph 2
[example link](https://brilliant.org)
> This is a quote
2 \times 3
2^{34}
a_{i1}
\frac{2}{3}
\sqrt{2}
\sum_{i=1}^3
\sin \theta
\boxed{123}
Comments
Sort by:
Top Newest@Aditya Raut Can you please give me some further sources than Codecademy. I guess you also learnt from there at first. But I want to know if there is any "advanced" source like CA. The course at CA is quite limited.
Log in to reply
I didn't learn from codeacademy, I learnt from 12 books and mainly, experimenting...
Log in to reply
@Aditya Raut r u a bio student or a cs student. u once posted about a cockroach.
Log in to reply
Log in to reply
Log in to reply
Log in to reply
That is great. Experimenting is the best way to learn. Especially in programming. I learn programming the same way.
Log in to reply
@Brock Brown @Agnishom Chattopadhyay @Pranjal Jain @Raghav Vaidyanathan
Log in to reply
There is a typo in cb(n,m) line 7. It should be
return '1'*n
Log in to reply
The standard way to convert a string in base $b$ to an integer is
int(string,b)
,by the wayLog in to reply
What is just happening!
So all I did was nothing but an $\text{exercise}$ of no real use, just use
int(str,b)
..... Why does this keep happening with me!Thank you btw, for telling this amazing shortcut, where'd you learn that?
Log in to reply
I don't exactly remember but I guess stackoverflow.
Log in to reply
Aditya, what's' your rank in JEE advanced?
Why don't you check your mail.
Log in to reply
he's in 12th now
Log in to reply