function c = getlsb(a)
% MATLAB Code Generation Library function.
%
% GETLSB Get a value of bit at LSB position
%
%    C = GETLSB(a)
%
%    C is of type ufix1 and has the same fimath of 'a'
%
%    A: must be a fi object matrix, array, or a scalar fi object
%    (signed or unsigned)
%
% The following cases will not be handled by this function:
%    a is not a fi object

%   Copyright 2002-2014 The MathWorks, Inc.
%#codegen

if isfixed(a)
    
    Fm = eml_fimath(a);

    lidx = 1;
    ridx = 1;

    eml_bitop_index_checks('getlsb', a,lidx,ridx);

    coder.inline('always');

    % outtype is always unsigned, size is same as slice length and no scaling
    slice_nt = numerictype(false, 1, 0);

    % If a has an attached fimath, then c will also have one
    % Otherwise c is a fimath-less fi
    if coder.const(eml_fimathislocal(a))
        c = fi(zeros(size(a)), 'numerictype', slice_nt, 'fimath', Fm);
    else
        c = fi(zeros(size(a)), 'numerictype', slice_nt);
    end


    for k = 1:numel(c)
        c(k) = eml_bitslice(a(k), coder.const(lidx-1), coder.const(ridx-1));
    end

else
    % non fi-fixedpoint not supported
    eml_invariant(false, ...
        'fixed:coder:fiFcnDTypeErrorFixPtOnly', 'GETLSB');
end
