# Path: commpy/utilities.py
# def dec2bitarray(in_number, bit_width):
#     """
#     Converts a positive integer or an array-like of positive integers to NumPy array of the specified size containing
#     bits (0 and 1).
# 
#     Parameters
#     ----------
#     in_number : int or array-like of int
#         Positive integer to be converted to a bit array.
# 
#     bit_width : int
#         Size of the output bit array.
# 
#     Returns
#     -------
#     bitarray : 1D ndarray of numpy.int8
#         Array containing the binary representation of all the input decimal(s).
# 
#     """
# 
#     if isinstance(in_number, (np.integer, int)):
#         return decimal2bitarray(in_number, bit_width).copy()
#     result = np.zeros(bit_width * len(in_number), np.int8)
#     for pox, number in enumerate(in_number):
#         result[pox * bit_width:(pox + 1) * bit_width] = decimal2bitarray(number, bit_width).copy()
#     return result
# 
# def bitarray2dec(in_bitarray):
#     """
#     Converts an input NumPy array of bits (0 and 1) to a decimal integer.
# 
#     Parameters
#     ----------
#     in_bitarray : 1D ndarray of ints
#         Input NumPy array of bits.
# 
#     Returns
#     -------
#     number : int
#         Integer representation of input bit array.
#     """
# 
#     number = 0
# 
#     for i in range(len(in_bitarray)):
#         number = number + in_bitarray[i] * pow(2, len(in_bitarray) - 1 - i)
# 
#     return number


from math import gcd
from numpy import array, zeros, arange, convolve, ndarray, concatenate
from commpy.utilities import dec2bitarray, bitarray2dec
                if x in full_cosets[i].elements:
                    t = array([1, full_cosets[i].elements[0]])[::-1]
                    for root in full_cosets[i].elements[1:]:
                        t2 = concatenate((zeros(len(t)-1), array([1, root]), zeros(len(t)-1)))
                        prod_poly = array([])
                        for n in range(len(t2)-len(t)+1):
                            root_sum = 0
                            for k in range(len(t)):
                                root_sum = root_sum ^ polymultiply(int(t[k]), int(t2[n+k]), self.m, self.prim_poly)
                            prod_poly = concatenate((prod_poly, array([root_sum])))
                        t = prod_poly[::-1]
                    minpol_list = concatenate((minpol_list, array([bitarray2dec(t[::-1])])))

        return minpol_list.astype(int)

# Divide two polynomials and returns the remainder
def polydivide(x, y):
    r = y
    while len(bin(r)) >= len(bin(y)):
        shift_count = len(bin(x)) - len(bin(y))
        if shift_count > 0:
            d = y << shift_count
        else:
            d = y
        x = x ^ d
        r = x
    return r

def polymultiply(x, y, m, prim_poly):
    x_array = dec2bitarray(x, m)

# Path: commpy/utilities.py
# def dec2bitarray(in_number, bit_width):
#     """
#     Converts a positive integer or an array-like of positive integers to NumPy array of the specified size containing
#     bits (0 and 1).
# 
#     Parameters
#     ----------
#     in_number : int or array-like of int
#         Positive integer to be converted to a bit array.
# 
#     bit_width : int
#         Size of the output bit array.
# 
#     Returns
#     -------
#     bitarray : 1D ndarray of numpy.int8
#         Array containing the binary representation of all the input decimal(s).
# 
#     """
# 
#     if isinstance(in_number, (np.integer, int)):
#         return decimal2bitarray(in_number, bit_width).copy()
#     result = np.zeros(bit_width * len(in_number), np.int8)
#     for pox, number in enumerate(in_number):
#         result[pox * bit_width:(pox + 1) * bit_width] = decimal2bitarray(number, bit_width).copy()
#     return result
# 
# def bitarray2dec(in_bitarray):
#     """
#     Converts an input NumPy array of bits (0 and 1) to a decimal integer.
# 
#     Parameters
#     ----------
#     in_bitarray : 1D ndarray of ints
#         Input NumPy array of bits.
# 
#     Returns
#     -------
#     number : int
#         Integer representation of input bit array.
#     """
# 
#     number = 0
# 
#     for i in range(len(in_bitarray)):
#         number = number + in_bitarray[i] * pow(2, len(in_bitarray) - 1 - i)
# 
#     return number


# Path: commpy/channelcoding/gfields.py
from math import gcd
from numpy import array, zeros, arange, convolve, ndarray, concatenate
from commpy.utilities import dec2bitarray, bitarray2dec

                if x in full_cosets[i].elements:
                    t = array([1, full_cosets[i].elements[0]])[::-1]
                    for root in full_cosets[i].elements[1:]:
                        t2 = concatenate((zeros(len(t)-1), array([1, root]), zeros(len(t)-1)))
                        prod_poly = array([])
                        for n in range(len(t2)-len(t)+1):
                            root_sum = 0
                            for k in range(len(t)):
                                root_sum = root_sum ^ polymultiply(int(t[k]), int(t2[n+k]), self.m, self.prim_poly)
                            prod_poly = concatenate((prod_poly, array([root_sum])))
                        t = prod_poly[::-1]
                    minpol_list = concatenate((minpol_list, array([bitarray2dec(t[::-1])])))

        return minpol_list.astype(int)

# Divide two polynomials and returns the remainder
def polydivide(x, y):
    r = y
    while len(bin(r)) >= len(bin(y)):
        shift_count = len(bin(x)) - len(bin(y))
        if shift_count > 0:
            d = y << shift_count
        else:
            d = y
        x = x ^ d
        r = x
    return r

def polymultiply(x, y, m, prim_poly):
    x_array = dec2bitarray(x, m)

    y_array = dec2bitarray(y, m)