def encodeVarint(fint):
    """ backward-encoded Mobipocket variable-width integer. """
    vint = 0
    bitpos = 0
    while bitpos < 32:
        vint |= (fint & 127) << bitpos
        if fint < 127:
            vint |= 128 << bitpos
            break
        fint >>= 7
        bitpos += 8
    return vint
