www.gusucode.com > fixedpoint 案例源码程序 matlab代码 > fixedpoint/CreateafiObjectWithNegativeFractionLengthExample.m

    %% Create a fi Object With Negative Fraction Length  
% When you use binary-point representation for a fixed-point number, the
% fraction length can be negative. In this case, there are implicit trailing
% zeros (for positive numbers) or ones (for negative numbers) between the
% binary point and the first significant binary digit. 
%
% Consider a signed value with a word length of 8, fraction length of –2
% and a stored integer value of 5. We can calculate the real-world value. 
% 
%  RealWorldValue = StoredInteger * 2 ^ -FractionLength
%  RealWorldValue = 5 * 2 ^ 2 = 20   

%% 
% Create a signed |fi| object with a value of |20|, a word length of 8 bits,
% and a fraction length of –2 bits. 

a = fi(20, true, 8, -2)  

%% 
% Get the stored integer value of |a|. 

a.int  

%% 
% Get the binary value of the stored integer. 
a.bin 

%%
% Because the fraction length is negative, the binary value of the stored
% integer is |00000101xx| , where |x| is a placeholder for implicit zeros.
% |000000010100| (binary) is equivalent to |20| (decimal).