我正在尝试将C语言中的无符号字符转换为Matlab代码,无符号字符向量填充了十六进制值。以下是C代码:
int main()
{
unsigned char value = 0xaa;
signed char temp;
// cast to signed value
temp = (signed char) value;
// if MSB is 1, then this will signed extend and fill the temp variable with 1's
temp = temp >> 7;
// AND with the reduction variable
temp = temp & 0x1b;
// finally shift and reduce the value
printf("%u",((value << 1)^temp));
}
我创建的 Matlab 函数用于执行同样的操作:
value = '0xaa';
temp = int8(value);
temp2 = int8(value);
temp = bitsra(temp,7);
temp = and(temp,'0x1b');
galois_value = xor(bitsll(temp2,1),temp);
disp(galois_value);
每一段代码中打印出来的值都不同,有人知道是怎么回事吗?
unsigned int temp = (value > SCHAR_MAX ? 0x1b : 0);
- M.M