#NEWLINE# def numberToByteArray( n , howManyBytes = None ) : #NEWLINE# #INDENT# 'Convert an integer into a bytearray, zero-pad to howManyBytes.\n\n    The returned bytearray may be smaller than howManyBytes, but will\n    not be larger.  The returned bytearray will contain a big-endian\n    encoding of the input integer (n).\n    ' #NEWLINE# if ( howManyBytes == None ) : #NEWLINE# #INDENT# howManyBytes = numBytes ( n ) #NEWLINE# #UNINDENT# b = bytearray ( howManyBytes ) #NEWLINE# for count in range ( ( howManyBytes - 1 ) , ( - 1 ) , ( - 1 ) ) : #NEWLINE# #INDENT# b [ howManyBytes ] = int ( ( n % 256 ) ) #NEWLINE# n >>= 8 #NEWLINE# #UNINDENT# return b