i have two array of chars of size 12 each having only 0's or 1's.
what i am trying to do is that in for loop

for(i=0;i<12;i++)
{
 int a=1starray[i];
 int b=2ndarray[i];
 int c=a^b
}

but every time c gets 0 only. iam not getting it why.
can anybody help me out.
thank you in advance

Recommended Answers

All 4 Replies

Are those characters '1' and '0' (ASCII values) or are they numeric 0 and 1? It makes a big difference.

i think they are numeric 1 and 0.
actually i transferred all the contents of a string into char.that string was binary conversion of an integer

String bin=Integer.toBinaryString(ihex);
			System.out.println(bin);
	
			if(bin.length()-12 > 0)
				orgpc=bin.substring(bin.length()-12);
			else
				orgpc=new String(bin);
			System.out.println(orgpc);
	
			char[] org=new char[12];
			for(i=0;i<12;i++)
			{
				org[i]=0;
			}
		
			if(orgpc.length()==12)
				orgpc.getChars(0,12,org,0);
			else if(orgpc.length()<12)
				orgpc.getChars(0,orgpc.length(),org,12-orgpc.length());
	
			char[] bhr1=new char[12];
			int n;
	
			for(n=0;n<6;n++)
	 			{bhr1[n]=0; System.out.println(bhr1[n]);   System.out.println(org[n]);}
			
			for(n=6;n<12;n++)
	 			{bhr1[n]=bhr[n-6];  System.out.println(org[n]);   System.out.println(org[n]);}
	 
			char[] xoredpc=new char[12];
	
			//System.out.println(org);
			//System.out.println(bhr1);
	
			for(int p=0;p<12;p++)
			{
	 			int a=org[p];
	 			int b=bhr1[p];
	 			int check=a^b;
	 			
	 			if(check==1)
	 				xoredpc[p]='1';
	
	 			else
	 				xoredpc[p]='0';
	 			System.out.println("XORED="+xoredpc[p]);
			}

chars are numeric values that are used to represent characters. You must always distinguish between the two, ie
char c = 0;
is not the same as
char c = '0';
in the second case c has the value 48.

From the API doc of Integer.toBinaryString
... The characters '0' ('\u0030') and '1' ('\u0031') are used as binary digits.
So your chars are '0' and '1', ASCII numeric values 48 and 49 respectively. The logical operators work with the numeric values, not the character representations, so you may need to rethink your code a bit.

thanks for information.
i figured out that i wrote somewhere

char arr[2]=0;

after making it '0' xor worked perfectly.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.