def test_big_integer_to_ba(self): b1 = BigInteger(8972340892734890723) ba = b1.ToByteArray() integer = BigInteger.from_bytes(ba, 'little') self.assertEqual(integer, 8972340892734890723) b2 = BigInteger(-100) b2ba = b2.ToByteArray() integer2 = BigInteger.from_bytes(b2ba, 'little') self.assertEqual(integer2, 65436) b3 = BigInteger(128) b3ba = b3.ToByteArray() self.assertEqual(b3ba, b'\x80\x00')
def test_big_integer_frombytes(self): b1 = BigInteger(8972340892734890723) ba = b1.ToByteArray() b2 = BigInteger.FromBytes(ba) self.assertEqual(b1, b2) self.assertTrue(b1.Equals(b2))
def GetHashCodeBytes(self): """ Get the hash code in bytes. Returns: bytes: """ bigint = BigInteger(self.GetHashCode()) return bigint.ToByteArray()
def test_big_integer_sign(self): b1 = BigInteger(3) b2 = BigInteger(0) b3 = BigInteger(-4) self.assertEqual(b1.Sign, 1) self.assertEqual(b2.Sign, 0) self.assertEqual(b3.Sign, -1) c1 = BigInteger(-100) c1_bytes = c1.ToByteArray() c2 = BigInteger.FromBytes(c1_bytes, signed=True) self.assertEqual(c2.Sign, -1) c2_unsigned = BigInteger.FromBytes(c1_bytes, signed=False) self.assertEqual(c2_unsigned.Sign, 1)