Popular recipes by Vishal Sapre http://code.activestate.com/recipes/users/4166412/2009-07-17T09:17:32-07:00ActiveState Code RecipesConverty decimal/integer number to binary string in Python (Python)
2009-07-17T09:17:32-07:00Vishal Saprehttp://code.activestate.com/recipes/users/4166412/http://code.activestate.com/recipes/576847-converty-decimalinteger-number-to-binary-string-in/
<p style="color: grey">
Python
recipe 576847
by <a href="/recipes/users/4166412/">Vishal Sapre</a>
(<a href="/recipes/tags/binary/">binary</a>, <a href="/recipes/tags/decimal/">decimal</a>, <a href="/recipes/tags/integer/">integer</a>, <a href="/recipes/tags/string/">string</a>).
</p>
<p>This is a very simple look-up based method for converting integer to binary string. In my tests, using 'timeit', its the fastest around. And with increasing value of input decimal number, it surpases any 'run time computation' based method doing the above.</p>
Reverse the byte order of an unsigned 'int' or 'long' number in Python (Python)
2008-08-15T14:03:30-07:00Vishal Saprehttp://code.activestate.com/recipes/users/4166412/http://code.activestate.com/recipes/576421-reverse-the-byte-order-of-an-unsigned-int-or-long-/
<p style="color: grey">
Python
recipe 576421
by <a href="/recipes/users/4166412/">Vishal Sapre</a>
(<a href="/recipes/tags/byte_order/">byte_order</a>, <a href="/recipes/tags/byte_order_reversal/">byte_order_reversal</a>, <a href="/recipes/tags/reverse/">reverse</a>, <a href="/recipes/tags/swap_byte_order/">swap_byte_order</a>).
Revision 5.
</p>
<p>Given an unsigned number, of type 'int' or 'long', this function returns a corresponding number of the same type, with its byte order reversed.
So if input = 0xABCDEF, then output = 0xEFCDAB</p>