<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def gray(num_bits):
 """ Generate the Gray code for `num_bits` bits. """

    last = 0
    x = 0
    n = 1 << num_bits
    while n > x:
        bit_string = bin(n + x ^ x // 2)[3:]
        value = int(bit_string, 2)
        yield bit_string, value, changed_bit_pos(last, value)
        last = value
        x += 1