function binString = float2binFixedSize( n , lengthWanted )
%FLOAT2BINFIXEDSIZE Summary of this function goes here
%   Detailed explanation goes here




%% [[ 1 ]] - VALIDIERUNG  >>  Fließkommazahl?
if ~isfloat( n )
    error('Es muss eine Fließkommazahl übergeben werden')
end




%% [[ 2 ]] - VORKOMMASTELLEN  >>  Errechnung mittels Hilfsfunktion
preFloatingPointBin  = dec2bin( fix(n) );



 

%% [[ 3 ]] - NACHKOMMASTELLEN  >>  eigener Algorithmus

postFloatingPointDec = fix ( (n - fix(n)) * 10^14 ) / 10^14;

counter = -1;

postFloatingPointBin = [];

decSizeOfCurrentPartialBinNumber = 0;

tolerance = 10^-12;


% Iterieren, bis Dualzahl und Dezimalzahl gleich groß
while (postFloatingPointDec - decSizeOfCurrentPartialBinNumber)  > tolerance  
    
   if decSizeOfCurrentPartialBinNumber  +  2 ^ counter   <   postFloatingPointDec
       
       postFloatingPointBin = [ postFloatingPointBin '1' ]; % "Dualstelle passt noch rein"
       
       % Größe der bisherigen, noch unvollständigen Duazahl erhöhen um die neue Stelle
       decSizeOfCurrentPartialBinNumber = decSizeOfCurrentPartialBinNumber + 2 ^ counter;
       
   else
       
       postFloatingPointBin = [ postFloatingPointBin '0' ]; % Dualstelle "passt nicht mehr rein"
       
   end%-if


counter = counter - 1;
    
end




%% [[ 4 ]] - VORZEICHEN  >>  als führendes Bit codieren

signBit = num2str( ~(n > 0) );




%% [[ 5 ]] - ZUSAMMENSETZEN  >>  von Vorzeichenbit, Vor- und Nachkommastelle
binString = [ signBit  preFloatingPointBin '.' postFloatingPointBin ];


%% [[ 6 ]] - ZURECHTSTUTZEN  >>  auf die geforderte Länge
binString = binString( 1 : lengthWanted + 1 );


end

