# MATLAB: getting the reminder of polynomial division

Discussion in 'Programmer's Corner' started by walid el masry, Jul 3, 2010.

1. ### walid el masry Thread Starter Active Member

Mar 31, 2009
132
0
An 8-bit field used to detect errors in the header.The transmitter shall calculate the HCS value for the first five bytes of the cell header, and insert the result into the HCS field (the last byte of the MAC header). It shall be the reminder of the division (Modulo 2) by the generator polynomial D^8 + D^2 + D + 1 of the polynomial D^8 multiplied by the content of the header excluding the HCS field."

how to do that in matlab ?

Last edited: Jul 4, 2010
2. ### walid el masry Thread Starter Active Member

Mar 31, 2009
132
0
thnx for all who tried to help me, the solution is

Code ( (Unknown Language)):
1.
2. % get the remoner of division of the input by genpol polynomials
3. function rem = binary_rem(input, genpol)
4. %input = [0 0 0 1 0 0 0 0 1 1 0 0 1 1 0 0 ];
5. %genpol= [1 0 0 0 0 0 1 1 1];
6. input = [input zeros(1,length(genpol)-1) 0];
7. temp=input(1:length(genpol));
8. for i=1:length(input)-length(genpol);
9.     if temp(1) == 1;
10.         q(i) = 1;
11.         output = xor(temp,genpol);
12.     else
13.         q(i) = 0;
14.         %output = xor(temp,not(genpol));
15.         output = temp;
16.     end
17.     temp = [output(2:end) input(length(genpol)+i)];
18. end
19.
20. rem = temp(1:end-1);
21. end
22.