matlab里二进制数的移位运算的函数
intersect:集合交集
ismember :是否集合中元素
setdiff :集合差集
setxor :集合异或(不在交集中的元素)
union :两个集合的并
unique :返回向量作为一个集合所有元素(去掉相同元素)
dec2bin(x) 是把十进制整数x变换为二进制
bin2dec(y) 是把二进制数y变换为十进制数
base2dec('x',a) 是把a进制数x变化为十进制数
dec2base(y,a) 是把十进制数y变化为a进制数
移位,循环,与,反等操作函数:
BITAND——对二进制数进行与操作;
BITOR——对二进制数进行或操作;
BITXOR——对二进制数进行异或操作;
BITSHIFT——对二进制数进行移位操作。
BITSHIFT——对二进制数进行移位操作。
C = BITSHIFT(A,K) returns the value of A shifted by K bits. A must be
an unsigned integer or an array of unsigned integers. Shifting by K
is the same as multiplication by 2^K. Negative values of K are allowed
and this corresponds to shifting to the right, or dividing by 2^ABS(K)
and truncating to an integer. If the shift causes C to overflow
the number of bits in the unsigned integer class of A, then the
overflowing bits are dropped.
C = BITSHIFT(A,K,N) will cause bits overflowing N bits to be dropped.
N must be less than or equal to the length in
bits of the unsigned integer class of A, e.g., N<=32 for UINT32.
Instead of using BITSHIFT(A,K,8) or another power of 2 for N, consider
using BITSHIFT(UINT8(A),K) or the appropriate unsigned integer class
for A.
Example:
Repeatedly shift the bits of an unsigned 16 bit value to the left
until all the nonzero bits overflow. Track the progress in binary.
a = intmax('uint16');
disp(sprintf('Initial uint16 value %5d is %16s in binary', ...
a,dec2bin(a)))
for i = 1:16
a = bitshift(a,1);
disp(sprintf('Shifted uint16 value %5d is %16s in binary',...
a,dec2bin(a)))
end