Dies ist Teil des Codes. Hier möchte ich die Ziffern mit xor vergleichen. So soll es "0111" geben, aber es gibt "111" als Ergebnis. Wie kann ich es beheben? So soll es "0111" geben, aber es gibt "111" als Ergebnis. Wie kann ich es beheben?C Binärzahlen mit xor vergleichen
1 and 1 = 0
1 and 0 = 1
0 and 1 = 1
0 and 0 = 0
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
int BinaryRepForDisk1=1101, BinaryRepForDisk2=1010, Disk3=0, xor1, xor2, power=0;
while(BinaryRepForDisk1!=0)
{
xor1=BinaryRepForDisk1%2;
xor2=BinaryRepForDisk2%2;
if(xor1==xor2)
{
Disk3=Disk3+pow(10,power)*0;
power++;
}
else
{
Disk3=Disk3+pow(10,power)*1;
power++;
}
BinaryRepForDisk1=BinaryRepForDisk1/10;
BinaryRepForDisk2=BinaryRepForDisk2/10;
}
printf("%d",Disk3);
system("pause");
return 0;
}
* 'int BinaryRepForDisk1 = 1101' * - dies ist keine Zahl, die binär dargestellt wird. Es ist eintausendeinhundertundeins. – axiac
'111' und' 0111' sind gleich. – jadhachem
@jadhachem: Ähm ... nein! – Olaf