<aside> <img src="/icons/home_gray.svg" alt="/icons/home_gray.svg" width="40px" /> Home
<Don’t Touch>
</aside>
def print_4byte_hex_chunks(n):
# Convert to hex and remove the '0x' prefix
hex_str = hex(n)[2:]
# Add leading zeros to make the length a multiple of 8
while len(hex_str) % 8 != 0:
hex_str = '0' + hex_str
# Split into 8-character chunks and return them as a joined string
return ' '.join([hex_str[i:i+8] for i in range(0, len(hex_str), 8)])
def hex_operations(hex1, hex2):
# Convert hex strings to Sage integers
num1 = Integer('0x' + hex1)
num2 = Integer('0x' + hex2)
# Calculate sum, difference, and multiplication
sum_result = num1 + num2
sub_result = num1 - num2
mul_result = num1 * num2
# Convert results to 4-byte hexadecimal units
sum_hex = print_4byte_hex_chunks(sum_result)
sub_hex = print_4byte_hex_chunks(sub_result)
mul_hex = print_4byte_hex_chunks(mul_result)
return sum_hex, sub_hex, mul_hex
# Sample hexadecimal numbers
hex1 = "efcc7196 5fcb6b5f"
hex2 = "6b5bc196 6478d1db"
sum_hex, sub_hex, mul_hex = hex_operations(hex1, hex2)
print(f"Sum: {sum_hex}")
print(f"Sub: {sub_hex}")
print(f"Mul: {mul_hex}")