Most viewed recipes tagged "base"http://code.activestate.com/recipes/tags/base/views/2011-11-21T19:58:14-08:00ActiveState Code RecipesConverts from decimal to any base ( between 2 and 26 ) (Python)
2011-02-24T00:33:07-08:00Shashwat Anandhttp://code.activestate.com/recipes/users/4172995/http://code.activestate.com/recipes/577586-converts-from-decimal-to-any-base-between-2-and-26/
<p style="color: grey">
Python
recipe 577586
by <a href="/recipes/users/4172995/">Shashwat Anand</a>
(<a href="/recipes/tags/algorithms/">algorithms</a>, <a href="/recipes/tags/base/">base</a>).
</p>
<p>This function takes in any base-10 integer and returns the string representation of that number in its specified base-n form.
The code was inspired from <a href="http://code.activestate.com/recipes/65212-convert-from-decimal-to-any-base-number/" rel="nofollow">http://code.activestate.com/recipes/65212-convert-from-decimal-to-any-base-number/</a> , thereby improving upon it.</p>
Random Binary List (Python)
2011-11-09T19:38:14-08:00Alexander James Wallarhttp://code.activestate.com/recipes/users/4179768/http://code.activestate.com/recipes/577944-random-binary-list/
<p style="color: grey">
Python
recipe 577944
by <a href="/recipes/users/4179768/">Alexander James Wallar</a>
(<a href="/recipes/tags/base/">base</a>, <a href="/recipes/tags/binary/">binary</a>, <a href="/recipes/tags/list/">list</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/numbers/">numbers</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/random/">random</a>, <a href="/recipes/tags/random_binary_list/">random_binary_list</a>).
</p>
<p>This recipe returns a list of size n such that the contents of the returned list are random 0s and 1s. It returns a random binary list of size n.</p>
Base Conversion decimal to base = len(map) (Python)
2008-08-20T05:01:39-07:00Mark Zitnikhttp://code.activestate.com/recipes/users/4166559/http://code.activestate.com/recipes/576435-base-conversion-decimal-to-base-lenmap/
<p style="color: grey">
Python
recipe 576435
by <a href="/recipes/users/4166559/">Mark Zitnik</a>
(<a href="/recipes/tags/base/">base</a>, <a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/decimal/">decimal</a>, <a href="/recipes/tags/sequence/">sequence</a>, <a href="/recipes/tags/web_site/">web_site</a>).
Revision 7.
</p>
<p>This code enable decimal base conversion according map length and a different char set.</p>
<p>Example:</p>
<ul>
<li>map = ['0','1'] base 2 10 -> 1010</li>
<li>map = ['a','b'] base 2 10 -> baba</li>
<li>map = ['a','b','c','d','e','f','g','h','i','j','k','l'] base 12 10 -> k</li>
<li>map = ['a','b','c','d','e','f','g','h','i','j','k','l'] base 12 100 -> ie</li>
</ul>
<p>this simple method can be used in web sites to hide a well known decimal sequence like user ids.</p>
Metric Prefix Symbol and Decimal Quiz (Python)
2009-10-11T18:39:58-07:00Daniel Sahahttp://code.activestate.com/recipes/users/4171644/http://code.activestate.com/recipes/576928-metric-prefix-symbol-and-decimal-quiz/
<p style="color: grey">
Python
recipe 576928
by <a href="/recipes/users/4171644/">Daniel Saha</a>
(<a href="/recipes/tags/base/">base</a>, <a href="/recipes/tags/decimal/">decimal</a>, <a href="/recipes/tags/metric/">metric</a>, <a href="/recipes/tags/prefix/">prefix</a>, <a href="/recipes/tags/symbol/">symbol</a>, <a href="/recipes/tags/units/">units</a>).
Revision 3.
</p>
<p>Quiz on the metric prefixs, symbols, and decimals associated with each other.</p>
Base Expansion/Conversion Algorithm Python (Python)
2011-11-21T19:58:14-08:00Alexander James Wallarhttp://code.activestate.com/recipes/users/4179768/http://code.activestate.com/recipes/577939-base-expansionconversion-algorithm-python/
<p style="color: grey">
Python
recipe 577939
by <a href="/recipes/users/4179768/">Alexander James Wallar</a>
(<a href="/recipes/tags/base/">base</a>, <a href="/recipes/tags/base16/">base16</a>, <a href="/recipes/tags/base2/">base2</a>, <a href="/recipes/tags/base_conversion/">base_conversion</a>, <a href="/recipes/tags/base_expansion/">base_expansion</a>, <a href="/recipes/tags/conversion/">conversion</a>, <a href="/recipes/tags/lists/">lists</a>, <a href="/recipes/tags/numbers/">numbers</a>, <a href="/recipes/tags/number_theory/">number_theory</a>, <a href="/recipes/tags/python/">python</a>).
Revision 3.
</p>
<p>This algorithm converts a base c number into a base b number. Parameters c and b are arbitrary are not constrained by any bounds. The input n is a list and the output is a list.</p>