Bit xor of two binary strings and conversion into decimal
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
lilly lord
am 19 Jun. 2020
Kommentiert: lilly lord
am 21 Jun. 2020
Hi, I have two large binary strings (e.g 256 bits each), then how to perform bit Xor operation and then convert the answer into decimal number.
str1='11010011110111110000110110111111';
str2='00011111001101011010001111100001';
str3=bitxor(str1,str2);
%%getting error in str3
3 Kommentare
Akzeptierte Antwort
James Tursa
am 19 Jun. 2020
Bearbeitet: James Tursa
am 19 Jun. 2020
The xor part as a logical vector result
result = str1 ~= str2;
Or if you wanted it as char:
str3 = char((str1 ~= str2) + '0');
For 8-bit chunks turned into decimal numbers:
result = 2.^(7:-1:0) * reshape(str1 ~= str2,8,[]);
7 Kommentare
James Tursa
am 20 Jun. 2020
So, can you tell me what exactly you have as inputs (size and class) and what exactly you want as an output (size and class)?
Weitere Antworten (1)
David Hill
am 19 Jun. 2020
Use java BigInteger
import java.math.*;
a=BigInteger(str1,2);
b=BigInteger(str2,2);
c=a.xor(b);%c will be the decimal BigInteger
Siehe auch
Kategorien
Mehr zu Logical 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!