我想对两个二进制数执行逻辑and
运算。我尝试使用 bitand
,但该函数只能用于 char
数据类型。
我想对两个二进制数执行and
。
例如:
a=1101;
b=1010;
那么a和b
的输出一定是
c=1000;
这是我尝试过的:
K=input('feed the value');
M=2^K;
S=input('feed the data');
disp(M);
s=dec2bin(S);
m=dec2bin(M-1);
q=bitand(s,m);
disp(q);
最佳答案
and i hav a prob that bitand is applicable only for data type char
这是错误的。 bitand
需要整数输入参数。
示例:
>> K=9
K =
8
>> L=12
L =
12
>> bitand(K,L)
ans =
8
关于matlab - 以及对两个二进制数的运算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22116224/