Popular recipes tagged "decimal" but not "binary"http://code.activestate.com/recipes/tags/decimal-binary/2013-08-22T07:15:47-07:00ActiveState Code RecipesContinued fractions (Python)
2013-08-22T07:15:47-07:00Glenn Hutchingshttp://code.activestate.com/recipes/users/4175415/http://code.activestate.com/recipes/578647-continued-fractions/
<p style="color: grey">
Python
recipe 578647
by <a href="/recipes/users/4175415/">Glenn Hutchings</a>
(<a href="/recipes/tags/decimal/">decimal</a>, <a href="/recipes/tags/fractions/">fractions</a>).
Revision 2.
</p>
<p>A class representing a <a href="https://en.wikipedia.org/wiki/Continued_fraction">continued fraction</a>.</p>
Complex Methods to Compute Pi in Python (Python)
2013-06-03T18:08:19-07:00Captain DeadBoneshttp://code.activestate.com/recipes/users/4184772/http://code.activestate.com/recipes/578548-complex-methods-to-compute-pi-in-python/
<p style="color: grey">
Python
recipe 578548
by <a href="/recipes/users/4184772/">Captain DeadBones</a>
(<a href="/recipes/tags/decimal/">decimal</a>, <a href="/recipes/tags/pi/">pi</a>, <a href="/recipes/tags/python/">python</a>).
</p>
<p>This script was written for an article I wrote about computing Pi with Python. This module uses the Decimal library. For more information <a href="http://thelivingpearl.com/2013/05/28/computing-pi-with-python/">How to Compute Pi in Python</a></p>
Archimedes Method for PI (arbitrary precision) (Python)
2013-03-02T21:56:42-08:00Bjorn Madsenhttp://code.activestate.com/recipes/users/4176352/http://code.activestate.com/recipes/578478-archimedes-method-for-pi-arbitrary-precision/
<p style="color: grey">
Python
recipe 578478
by <a href="/recipes/users/4176352/">Bjorn Madsen</a>
(<a href="/recipes/tags/decimal/">decimal</a>, <a href="/recipes/tags/math/">math</a>, <a href="/recipes/tags/pi/">pi</a>, <a href="/recipes/tags/precision/">precision</a>, <a href="/recipes/tags/python3/">python3</a>).
</p>
<p>The code below incorporates the newly revised python 3.3.0 decimal module to permit arbitrary precision (<a href="http://docs.python.org/3/library/decimal.html%29" rel="nofollow">http://docs.python.org/3/library/decimal.html)</a></p>
<p>The recipe was originally by FB35 from <a href="http://code.activestate.com/recipes/576981-archimedes-method-for-calculating-pi/" rel="nofollow">http://code.activestate.com/recipes/576981-archimedes-method-for-calculating-pi/</a> </p>
Decimal Number To Byte(s) And String To Byte(s) Converter. (Python)
2012-01-24T21:11:47-08:00Barry Walkerhttp://code.activestate.com/recipes/users/4177147/http://code.activestate.com/recipes/578025-decimal-number-to-bytes-and-string-to-bytes-conver/
<p style="color: grey">
Python
recipe 578025
by <a href="/recipes/users/4177147/">Barry Walker</a>
(<a href="/recipes/tags/bytes/">bytes</a>, <a href="/recipes/tags/converter/">converter</a>, <a href="/recipes/tags/decimal/">decimal</a>, <a href="/recipes/tags/linux/">linux</a>, <a href="/recipes/tags/string/">string</a>, <a href="/recipes/tags/windows/">windows</a>).
</p>
<p>A function to convert decimal integer numbers, (from 0 to 255), into byte(s) format.
Another function calling the above function to convert ASCII strings into byte(s) format.</p>
<p>Python 3.1.3 (r313:86834, Nov 28 2010, 10:01:07)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.</p>
<pre class="prettyprint"><code>>>> exec(open('/home/G0LCU/Desktop/Code/d2b.py').read())
>>> a=78
>>> type(a)
<class 'int'>
>>> b=d2b(a)
>>> print(b)
b'N'
>>> type(b)
<class 'bytes'>
>>> text="\x00(C)2012, B.Walker, G0LCU.\xFF"
>>> len(text)
27
>>> type(text)
<class 'str'>
>>> newtext=t2b(text)
>>> len(newtext)
27
>>> print(newtext)
b'\x00(C)2012, B.Walker, G0LCU.\xff'
>>> type(newtext)
<class 'bytes'>
</code></pre>
<p>It requires NOTHING special at all to work and can be run like above or imported from
the correct "Lib" drawer/folder/directorfy as:-</p>
<pre class="prettyprint"><code>>>> import d2b
</code></pre>
<p>And when imported called as:-</p>
<pre class="prettyprint"><code>>>> d2b.d2b(some_number, optional_some_other_mumber)<RETURN/ENTER>
</code></pre>
<p>OR</p>
<pre class="prettyprint"><code>>>> d2b.t2b(some_ASCII_string)<RETURN/ENTER>
</code></pre>
<p>Read the code for much more information...</p>
<p>Issued under the GPL2 licence.</p>
<p>Enjoy finding simple solutions to often very difficult problems.</p>
<p>Bazza, G0LCU.</p>
Unit Conversions Using Decimal (Python)
2011-04-13T06:55:05-07:00Dave Baileyhttp://code.activestate.com/recipes/users/4168479/http://code.activestate.com/recipes/577652-unit-conversions-using-decimal/
<p style="color: grey">
Python
recipe 577652
by <a href="/recipes/users/4168479/">Dave Bailey</a>
(<a href="/recipes/tags/conversions/">conversions</a>, <a href="/recipes/tags/decimal/">decimal</a>, <a href="/recipes/tags/units/">units</a>).
</p>
<p>A table driven routine generates a unit conversion module and a doctest file. The generated module uses the Decimal class to create unit conversion classes which uses class properties to perform the conversion. conversion.py supplies the following classes:
Distance
Area
Volumn
Time
Velocity
Acceleration
Mass
Force
Weight
Pressure
Frequency
Power
Temperature</p>
<p>New classes and additional units can easily be created by adding to the table.</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 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>