def bigIntToArray_v1(value): result = [] while True: result.insert(0, value % 256) value = value // 256 if value == 0: break return result def bigIntToArray_v2(value): result = [] while True: result.insert(0, value & 0b1111_1111) value = value >> 8 if value == 0: break return result
Test
expected = [ 30, 119, 10, 234, 151, 91, 69, 198, 85, 193, 130, 94, 213, 16, 109, 151, 14, 129, 143, 64, 171, 172, 190, 28, 152, 247, 78, 21, 94, 76, 93, 58 ] result1 = bigIntToArray_v1(13779715600237310799632842054081955307819773220415101057149384327455163833658) result2 = bigIntToArray_v2(13779715600237310799632842054081955307819773220415101057149384327455163833658) print(result1 == expected) print(result2 == expected) print( bytearray(result1) ) print( bytearray(result2) )
structmodule: docs.python.org/library/struct.html