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

    %% Set the Bit at a Certain Position in a Vector  

% Copyright 2015 The MathWorks, Inc.


%% 
% Consider the following fixed-point vector with word length 4 and fraction
% length 0. 
a = fi([0 1 8 2 4],0,4,0);
disp(bin(a))  

%% 
% In each element of vector |a|, set the bits at position 2 to |1|. 
c = bitset(a,2,1);
disp(bin(c))