def rgb_to_hex(rgb):
    """
    Converts RGB tuple to hexadecimal string
    :param rgb: tuple(float, float, float): color tuple (R, G, B)
    :return: str, hexadecimal string (eg. 2F2F2F)
    """

    ret = ''.join([hex(h)[2:].upper().zfill(2) for h in rgb])
    if len(ret) == 8:
        # Move last two characters to the beginning
        return ret[-2] + ret[:2]

    return ret