function rulenumber=rulenumberencoder(rulenumberbinary,rulecolors, rule)
% rulenumberbinary must be an array!
if strcmp(rule, 'rules_twod_totalistic') || strcmp(rule, 'rules_twod_totalistic_wrap')
rulecolors=rulecolors+1; end; % these 2 rules adjust rule colors in their computation
[rulenumberbinaryrows,rulenumberbinarycols]=size(rulenumberbinary);
rulenumber=0;
for checking=0:rulenumberbinarycols-1;
rulenumber=(rulenumberbinary(end-checking) * rulecolors^checking) + rulenumber;
end;
if strcmp(rule, 'rules_twod_totalistic') || strcmp(rule, 'rules_twod_totalistic_wrap')
rulecolors=rulecolors-1; end; % these 2 rules adjust rule colors in their computation