def encode_hex(self, hex_str):
        """Converts a hexadecimal string (e.g. a MongoDB id) to a hashid.

        :param hex_str The hexadecimal string to encodes

        >>> Hashids.encode_hex('507f1f77bcf86cd799439011')
        'y42LW46J9luq3Xq9XMly'
        """
        numbers = (int('1' + hex_str[i:i+12], 16)
                   for i in range(0, len(hex_str), 12))
        try:
            return self.encode(*numbers)
        except ValueError:
            return ''