return list which expresses on/off status of specified bit [usage] [status_list] = vb_util_get_bit_status(data, target_bit, bit_len) [input] data : <required> data : [1 x Nsample] target_bit : <optional> target bit list [1:16] : [1 x N] or [N x 1] e.g. [1 2 3] bit_len : <optional> data bit length [24] [output] status_list : bit status list [Ntarget_bit x Nsample] [note] @see vb_bitand_ex.m [history] 2007-08-23 (Sako) initial version Copyright (C) 2011, ATR All Rights Reserved. License : New BSD License(see VBMEG_LICENSE.txt)
0001 function [status_list] = vb_util_get_bit_status(data, target_bit, bit_len) 0002 % return list which expresses on/off status of specified bit 0003 % [usage] 0004 % [status_list] = vb_util_get_bit_status(data, target_bit, bit_len) 0005 % [input] 0006 % data : <required> data 0007 % : [1 x Nsample] 0008 % target_bit : <optional> target bit list [1:16] 0009 % : [1 x N] or [N x 1] e.g. [1 2 3] 0010 % bit_len : <optional> data bit length [24] 0011 % [output] 0012 % status_list : bit status list [Ntarget_bit x Nsample] 0013 % [note] 0014 % @see vb_bitand_ex.m 0015 % [history] 0016 % 2007-08-23 (Sako) initial version 0017 % 0018 % Copyright (C) 2011, ATR All Rights Reserved. 0019 % License : New BSD License(see VBMEG_LICENSE.txt) 0020 0021 % --- CHECK ARGUMENTS --- % 0022 if ~exist('data', 'var') data = []; end 0023 if ~exist('target_bit', 'var') target_bit = []; end 0024 if ~exist('bit_len', 'var') bit_len = []; end 0025 [data, target_bit, bit_len] = inner_check_arguments(data, target_bit, bit_len); 0026 0027 % --- MAIN PROCEDURE --------------------------------------------------------- % 0028 % 0029 status_list = zeros(size(target_bit,2), size(data,2)); 0030 0031 list_cnt = 1; 0032 for cur_bit = target_bit 0033 shift_len = cur_bit - 1; 0034 focus_bit = bitshift(1,shift_len); 0035 status = vb_bitand_ex(data, focus_bit, bit_len); 0036 status_list(list_cnt,find(status)) = 1; 0037 list_cnt = list_cnt + 1; 0038 end 0039 0040 return; 0041 % 0042 % --- END OF MAIN PROCEDURE -------------------------------------------------- % 0043 0044 % --- INNER FUNCTIONS -------------------------------------------------------- % 0045 % 0046 % --- inner_check_arguments() 0047 % 0048 function [data, target_bit, bit_len] = ... 0049 inner_check_arguments(data, target_bit, bit_len) 0050 func_ = mfilename; 0051 0052 if isempty(data) 0053 error('(%s)data is a required parameter', func_); 0054 end 0055 0056 if isempty(target_bit) 0057 % error('(%s)target_bit is a required parameter', func_); 0058 target_bit = 1:16; 0059 end 0060 0061 target_bit = vb_util_arrange_list(target_bit, 1); 0062 0063 if isempty(bit_len) 0064 bit_len = 24; 0065 end 0066 0067 err_bit = find(target_bit > bit_len); 0068 if ~isempty(err_bit) 0069 warning('(%s)there are some bad bit : %d\n', err_bit); 0070 target_bit(err_bit) = []; 0071 end 0072 0073 return; 0074 % 0075 % --- end of inner_check_arguments() 0076 % 0077 % --- END OF INNER FUNCTIONS ------------------------------------------------- % 0078 0079 %%% END OF FILE %%%