function ret = crcConvInits(initbits, polybit)
%

%  Copyright 2012 The MathWorks, Inc.

%  The HDL optimized CRC Generator block feeds the message into the least
%  significant bit (LSB) of the checksum shift register and requires
%  augmenting the message with CRC_length zeros.
%  The CRC calculation in the IEEE 802.11 reads the message into the most
%  significant bit (MSB) of the checksum shift register and processes the
%  message without padding zeros
% This function converts the initial state when using HDL optimizied CRC
% blocks to implement CRC calculation in the IEEE  802.11 standard.

%  Both inputs are row vector of binary values
% 

order = length(polybit);

for ii = 0:(order-1)
    bit = initbits(end);

    if bit ~= 0
        initbits = xor(initbits, polybit); % bitwise xor with polynomial
    end

    % shift right one bit
    initbits = [0 initbits(1:end-1)];
    % wrap-around
    if bit ~= 0
        initbits(1) = 1;
    end
end

ret = initbits;