function [Dec, CodeS] = scaleFactorCode(val,N)
%SCALEFACTORCODE computes the binary string corresponding to the scale
%factor
%  [Dec, CodeS] = scaleFactorCode(val,N), val should be positive and N in the
%  range [0 1]

q = 1/2^N;          % Quantum interval

val=abs(val);

if val >1, val=1; end

Dec=round(ceil(val./q)-0.5);
remd = 0;
CodeS='';
quot=Dec-1;
while (quot>0),
   remd = mod(quot,2);
   quot = floor(quot/2);
   CodeS = [num2str(remd) CodeS];
end
for i=1:(N-length(CodeS)),
     CodeS = ['0' CodeS];
end
