code: def _to_binpoly(x):
          '''Convert a Galois Field's number into a nice polynomial'''
          if x <= 0: return "0"
          b = 1 # init to 2^0 = 1
          c = [] # stores the degrees of each term of the polynomials
          i = 0 # counter for b = 2^i
          while x > 0:
              b = (1 << i) # generate a number power of 2: 2^0, 2^1, 2^2, ..., 2^i. Equivalent to b = 2^i
              if x & b : # then check if x is divisible by the power of 2. Equivalent to x % 2^i == 0
                  # If yes, then...
                  c.append(i) # append this power (i, the exponent, gives us the coefficient)
                  x ^= b # and compute the remainder of x / b
              i = i+1 # increment to compute the next power of 2
          return " + ".join(["x^%i" % y for y in c[::-1]]f _to_binpoly(x):
          '''Convert a Galois Field's number into a nice polynomial'''
          if x <= 0: return "0"
          b = 1 # init to 2^0 = 1
          c = [] # stores the degrees of each term of the polynomials
          i = 0 # counter for b = 2^i
          while x > 0:
              b = (1 << i) # generate a number power of 2: 2^0, 2^1, 2^2, ..., 2^i. Equivalent to b = 2^i
              if x & b : # then check if x is divisible by the power of 2. Equivalent to x % 2^i == 0
                  # If yes, then...
                  c.append(i) # append this power (i, the exponent, gives us the coefficient)
                  x ^= b # and compute the remainder of x / b
              i = i+1 # increment to compute the next power of 2
          return " + ".join(["x^%i" % y for y in c[::-1]])
docs: Convert a Galois Field's number into a nice polynomial