Convert a real number to its fixed representation so 
    that it can be written into a 32 bit register.
    @param real: the real number to be converted into fixed representation
    @param conv: conv structre with conversion specs
    @return: the fixed representation of the real number 
    @raise ConverisonError: if conv structre can't handle the real number.
    @todo: Better error detection and management of unsupported 
    operations and arguments

def real2fix(real, conv):
    """
    Convert a real number to its fixed representation so 
    that it can be written into a 32 bit register.
    @param real: the real number to be converted into fixed representation
    @param conv: conv structre with conversion specs
    @return: the fixed representation of the real number 
    @raise ConverisonError: if conv structre can't handle the real number.
    @todo: Better error detection and management of unsupported 
    operations and arguments
    """
    if not conv["signed"] and real < 0:
        raise ConversionError("cannot convert " + 
                str(real) + " to unsigned representation")
    if real < 0:
        sign = 1
        real = real - conv["int_min"] 
    else:
        sign = 0
    int_val, dec_val = divmod(abs(real), 1)
    int_val = int(int_val)
    int_val = int_val & (conv["int_mask"] >> conv["bin_point"])
    val = int_val
    dec = 0
    dec = dec_val // conv["dec_step"]
    if dec > conv["dec_mask"]:
        dec = conv["dec_mask"]
    dec_val = dec * conv["dec_step"]
    val += dec_val
    if (val - real) > (real - val + conv["dec_step"]):
        dec -= 1
    if sign == 1:
        return conv["sign_mask"] + ((int_val << conv["bin_point"]) &
                conv["int_mask"]) + dec
    else:
        return ((int_val << conv["bin_point"]) & conv["int_mask"]) + dec