import struct


def binary_cast(data, input_fmt, output_fmt):
    """Transform the input data from input binary format to output binary format"""
    # Pack in binary format
    p = struct.pack(input_fmt, *data)
    # Unpack into new format
    return struct.unpack(output_fmt, p)