bitand 按位与操作
a = 7;
b = bitand(10,a);
disp(dec2bin(a,8)); %ans = 00000111
disp(dec2bin(b,8)); %ans = 00000010
bitcmp 获取数据的补码
bitcmp(uint8(99)) %ans = 156
bitxor(99,255), %ans = 156
bitget获取二进制位
bitget(uint8(13), 4:-1:1), %ans = 1 1 0 1
bitget(uint8(13), 8:-1:1), %ans = 0 0 0 0 1 1 0 1
bitor按位或操作
a = 15;
b = bitor(10,a);
disp(dec2bin(a,8)); %ans = 00001111
disp(dec2bin(b,8)); %ans = 00001111
bitset 设置指定bit位
bitset(uint8(9), 5),%ans = 25 将9的第5位设置为1
bitshift 移位操作
bitshift(12, 2), %ans = 48 右移
bitshift(12, -2),%ans = 3 左移
bitxor 按位异或(取反)
a = 15;
b = bitxor(10,a);
disp(dec2bin(a,8)); ans = 00001111
disp(dec2bin(b,8)); ans = 00000101
dec2bin 十进制转换为二进制
bin2dec 二进制转换为十进制 %bin2dec('010111')
dec2hex 十进制转换为十六进制
hex2dec 十六进制转换为十进制%hex2dec('3ff')