calculate checksum for the input vector

i need to calculate checksum value for given vector. when i try to compile the code below i receive 14 error all related to the following Function 'Embedded MATLAB Function' (#18.1210.1225), line 49, column 18: "bitand(value,1)"
similar error type is for bitshift
appreciate the solution for this problem
thanks in advance
function CRC = fcn(input_value, CRC_int)
CRC = CRC_int;
l = numel(input_value);
for j = 1:l
if j == 1
value = bitshift(input_value(j),-1);
else
value = input_value(j)
m = (bitand(value,1) && bitand(CRC,1));
n = (bitand(value,1) || bitand(CRC,1));
if m == 1
CRC(j) = bitshift(CRC, -1);
value = bitshift(value, -1);
elseif m == 0 && n ~=1
CRC = bitshift(CRC, -1);
value = bitshift(value, -1);
elseif n == 1
CRC_temp = bitshift(CRC, -1);
CRC = bitxor(CRC_temp,CRC_int);
value = bitshift(value, -1);
end
end
CRC = CRC;
for i = 1:7
if (bitand(value,1) && bitand(crc_var,1))
CRC = bitshift(CRC, -1);
value = bitshift(value, -1);
elseif ((bitand(value,1) == 0) && (bitand(CRC,1) == 0))
CRC = bitshift(CRC, -1);
value = bitshift(value, -1);
elseif (bitand(value,1) || bitand(CRC, 1))
CRC_temp = bitshift(CRC, -1);
CRC = bitxor(CRC_temp,CRC_int);
value = bitshift(value, -1);
end
end
%crc_var = crc_var
% CRC = dec2hex(CRC);
end

답변 (2개)

Fangjun Jiang
Fangjun Jiang 2011년 12월 11일

0 개 추천

In R2007b, when used in Embedded MATLAB Function, bitand() doesn't support floating-point input. The arguments must belong to an integer class.

댓글 수: 3

M
M 2011년 12월 11일
thank you Fangiun...how can i avoid it?
Fangjun Jiang
Fangjun Jiang 2011년 12월 11일
You need to define your variable "value" as integer class, as well as the constant,e.g. bitand(int32(value),int32(1))
Jan
Jan 2011년 12월 12일
Or you use FLOOR(x/2) instead of BITSHIFT(x, -1). And REM(x, 2) is faster than BITAND(x, 1).

댓글을 달려면 로그인하십시오.

M
M 2011년 12월 12일

0 개 추천

Fangjun / Jan thank you for your hints....
the final answer that works for me is the following
function crc_var = fcn(input_value)
ply =uint16(hex2dec('8408'));
crc_var =uint16(0);
value = uint16(0);
l = numel(input_value);
for j = 1:l
value = uint16(input_value(j))
for i = 1:8
% x = and(value,one)
% y = and (crc_var,one)
m = (bitand(value,1) && bitand(crc_var,1))
n = (bitand(value,1) || bitand(crc_var,1))
if (m == 1 || (m == 0 && n ~=1))
crc_var = bitshift(crc_var, -1)
value = bitshift(value, -1)
elseif (n == 1)
crc_var_temp = bitshift(crc_var, -1)
crc_var = bitxor(crc_var_temp,ply)
value = bitshift(value, -1)
end
end
%crc_var = crc_var
crc_var_h = dec2hex(crc_var)
end

댓글 수: 2

Fangjun Jiang
Fangjun Jiang 2011년 12월 12일
So I assume the cause is due to the fact that you need to use integer class inputs for bitand() in EMC. Once you defined 'value' and 'crc_var' as uint16, the constant 1 is automatically casted.
M
M 2011년 12월 14일
seams to be the case....

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Numeric Types에 대해 자세히 알아보기

태그

질문:

M
M
2011년 12월 11일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by