function E=norm_check(E,K,flagE)

normE=sqrt(E'*E);
if abs(1-normE)>10^(-3)
    flag=zeros(size(flagE));
    pos_i=[];
    for i=1:K
        flag(i)=parity_check(abs(round(10^4*E(i))));
        if(flag(i)~=flagE(i))
            pos_i=[pos_i i];
        end
    end
    if length(pos_i)==1       
        if pos_i==1
            ind=2:K
        elseif pos_i==K
            ind=1:K-1
        else 
            ind=[1:pos_i-1 pos_i+1:K];
        end
        E(pos_i)=sign(E(pos_i))*sqrt(1-sum(E(ind)'*E(ind)));
    end
end