How can i XOR these two numbers?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Darsana P M
am 24 Okt. 2017
Kommentiert: Darsana P M
am 24 Okt. 2017
I have 2 sets of values: X =
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
U =
01011000
11100010
11111100
11001110
11111010
01111110
00110000
01100001
00110110
01111111
00011101
01010111
10100100
11100111
01000101
01011010
I want to XOR X and U.
I tried value=xor(X-'0',U-'1');
But i got an error. What must I do?
3 Kommentare
Jan
am 24 Okt. 2017
Bearbeitet: Jan
am 24 Okt. 2017
@Darsana P: No, it doesn't. It would work only if the inputs are char vectors:
X = '11100010';
But if X is a numerical vector already, subtracting '0' is meaningless. Subtracting '1' is not useful at all. In other words: "- '0'" is used to convert a char vector containing digits to a numerical vector containing the corresponding numbers.
Copying some code, which you do not understand, is guessing. Guessing is not useful for programming. You can check, what you are doing easily:
X - '0'
U - '1'
The result looks weird, doesn't it? But this works directly:
X = [1 1 1 0 0 0 1 0];
U = [0 0 0 0 0 0 0 0];
val = xor(X, U);
Well, xor'ing with zeros is not that interesting.
Akzeptierte Antwort
Jan
am 24 Okt. 2017
Bearbeitet: Jan
am 24 Okt. 2017
What are the types of X and U? Are they double or char vectors? Please post the input, such that it can be used by copy&paste.
X = [0; 0; 1] ;
U = [0 1 0 1 1 0 0 0; ...
1 1 1 0 0 0 1 0; ...
1 1 1 1 1 1 0 0];
Result = [U(:, 1:end-1), xor(X, U(:, end))]
Or perhaps:
X = ['0'; '0'; '1'] ;
U = ['01011000'; ...
'11100010'; ...
'11111100'];
Xd = X - '0'; % Convert CHAR '01' to DOUBLE [0, 1]
Ud = X - '0';
Result = [Ud(:, 1:end-1), xor(Xd, Ud(:, end))]
It would be easier to find a solution if you explain, what you want as result.
3 Kommentare
Jan
am 24 Okt. 2017
@Darsana P M: This is still no valid Matlab code. What does
U =[01011000
11100010]; % Abbreviated
mean? Numbers do not have leading zeros. So perhaps this is a char matrix?
U =['01011000'; ...
'11100010'];
The quotes are really important here. Or perhaps you mean a numerical matrix:
U =[0 1 0 1 1 0 0 0; ...
1 1 1 0 0 0 1 0];
I still assume that your problem is based on a confusion of the types. So please concentrate on this detail.
{'00', '00'} is a very strange input for an AES encryption. Perhaps these are HEX numbers? It is much easier to let AES operate on bytes, UINT8 arrays. Because the bit pattern is completely mixed by this encryption, operating with bit matrices (in which type ever) seems odd here.
Weitere Antworten (1)
KSSV
am 24 Okt. 2017
X = [0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1] ;
U =[01011000
11100010
11111100
11001110
11111010
01111110
00110000
01100001
00110110
01111111
00011101
01010111
10100100
11100111
01000101
01011010] ;
res = xor(num2str(X),num2str(U))
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!