ガロア体での 2 の乗算から Matlab の C コードを転写しています。問題は、私の matlab コードが C コードと同じ値を表示していないことです。どうやらすべて問題ありません。コードの下にある C コードの適応を識別するために、matlab のコードにコメントを付けました。
子:
#include <stdio.h>
#include <stdlib.h>
int main()
{
unsigned char value = 0xaa;
signed char temp;
// cast to signed value
temp = (signed char) value;
printf("\n%d",temp);
// if MSB is 1, then this will signed extend and fill the temp variable with 1's
temp = temp >> 7;
printf("\n%d",temp);
// AND with the reduction variable
temp = temp & 0x1b;
printf("\n%d",temp);
// finally shift and reduce the value
printf("\n%d",((value << 1)^temp));
}
出力:
-86
-1
27
335
マットラボ:
hex = uint8(hex2dec('1B')); % define 0x1b
temp = uint8(hex2dec('AA')); % temp = (signed char) value;
disp(temp);
value = uint8(hex2dec('AA')); % unsigned char value = 0xaa
temp = bitsra(temp,7); % temp = temp >> 7;
disp(temp);
temp = bitand(temp,hex); % temp = temp and 0x1b
disp(temp);
galois_value = bitxor(bitsll(value,1),temp); % ((value << 1)^temp)
disp(galois_value); % printf ("\n%u",...)
出力:
170
1
1
85
C コードは正しく動作%d
します。コードの冒頭でキャストされているため、変数の整数値を表示するために C コードを出力しています。
誰かが何が起こっているのか知っています