If suppose I have 2 inputs,
x=58 B2 43 1B C0 BE DE 02 55 0F 40 23 89 69 EC 78 (hexadecimal values)
y=00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01
The answer will be:
(x xor y)= 58b2431bc0bede02550f40238969ec79
How to write the matlab code for this xor operation??

 採用された回答

Walter Roberson
Walter Roberson 2017 年 11 月 19 日

0 投票

x = uint8(sscanf('58 B2 43 1B C0 BE DE 02 55 0F 40 23 89 69 EC 78', '%x'));
y = uint8(sscanf('00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01', '%x'));
xory = bitxor(x,y);
sprintf('%02x ', xory)

5 件のコメント

Darsana P M
Darsana P M 2017 年 11 月 19 日
Thank you sir
Darsana P M
Darsana P M 2017 年 11 月 19 日
Sir,how to get the msb of x??
Walter Roberson
Walter Roberson 2017 年 11 月 19 日
bitget(x, 8)
or
x >= 128
Darsana P M
Darsana P M 2017 年 11 月 19 日
I got an error, Undefined function 'bitget' for input arguments of type 'char'.
Walter Roberson
Walter Roberson 2017 年 11 月 19 日
x = '58 B2 43 1B C0 BE DE 02 55 0F 40 23 89 69 EC 78';
y = '00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01';
x_numeric = uint8(sscanf(x, '%x'));
y_numeric = uint8(sscanf(y, '%x'));
xory_numeric = bitxor(x_numeric, y_numeric);
xory_char = sprintf('%02x ', xory_numeric);
x_msb_numeric = bitget(x_numeric, 8);
x_msb_char = sprintf('%d ', x_msb_numeric);

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMultidimensional Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by