Python - Convert Bytearray to integer
<p>Hello is there a faster way than the one below to convert a bytearray to integer and vice versa in python? I am seeking for a solution which will allow me to speed up the execution time of my scripts.</p>

<p>Thank you.</p>

<pre><code>def bytesToNumber(self,b):
    total = 0
    multiplier = 1
    for count in xrange(len(b)-1, -1, -1):
        byte = b[count]
        total += multiplier * byte
        multiplier *= 256
    return total


def numberToByteArray(self,n, howManyBytes=None):
    if howManyBytes == None:
        howManyBytes = numBytes(n)
    b = bytearray(howManyBytes)
    for count in xrange(howManyBytes-1, -1, -1):
        b[count] = int(n % 256)
        n &gt;&gt;= 8
    return b
</code></pre>