Help for this.
Re: Help for this.
Yes brother I got many ideas from this.thanks for your help.but I have some questions about arrays.I will ask them in a new topic.
Re: Help for this.
Code: Select all
char c='C'; // note that ASCII value of C is 67
int num1 = 1, num2 = 2, num3 = 3;
float x = 0.5f, y = 2.5f;
System.out.println((x > y) ^ (num1 != num2));
please explain what happen in this line condition..(x > y) ^ (num1 != num2)
Re: Help for this.
Code: Select all
char c='C'; // note that ASCII value of C is 67
int num1 = 1, num2 = 2, num3 = 3;
float x = 0.5f, y = 2.5f;
System.out.println(num1 | num2);
It is little hard to get in to my mind.can you please tell me about it & about this bit wise operators..
please explain what happen in this line System.out.println(num1 | num2); why it give us out put as 3?
Re: Help for this.
^ is the bitwise XOR operator.G-sparkZ wrote:can you please tell me friend...in this code what"^" means..?????Code: Select all
char c='C'; // note that ASCII value of C is 67 int num1 = 1, num2 = 2, num3 = 3; float x = 0.5f, y = 2.5f; System.out.println((x > y) ^ (num1 != num2));
please explain what happen in this line condition..(x > y) ^ (num1 != num2)
The result of (x > y) is either 0 or 1. If x > y, the output of (x > y) is 1.
If x <= y {that is NOT (x > y) }, the result of (x > y) is 0.
So you now understand that (x > y) outputs either 0 or 1.
Lets take the other part (num1 != num2).
This of cause outputs either 0 or 1. If num1 not equals to num2, it outputs 1. Else (that is num1 == num2) it outputs 0.
Say (x > y) is A and (num1 != num2) is B. Then we have A ^ B.
The truth table of XOR is below.
X | Y | Result |
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 0 |
x = 0.5f, y = 2.5f, so (x > y) is false (0)
num1 = 1, num2 = 2, so (num1 != num2) is true (1)
0 XOR 1 = 1
Re: Help for this.
You need to learn boolean algebra (very easy) about AND, OR, XOR, NOT, NAND, NOR operators. Read this one to understand the truth table for these operations. http://en.wikipedia.org/wiki/Logic_gate#SymbolsG-sparkZ wrote:I got this code from my friend about bit wise operators.Code: Select all
char c='C'; // note that ASCII value of C is 67 int num1 = 1, num2 = 2, num3 = 3; float x = 0.5f, y = 2.5f; System.out.println(num1 | num2);
It is little hard to get in to my mind.can you please tell me about it & about this bit wise operators..
please explain what happen in this line System.out.println(num1 | num2); why it give us out put as 3?
The pipe symbol (|) is used to denote bitwise OR operation.
The truth table for OR operation is as below.
X | Y | Result |
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 1 |
Lets convert 57(dec) to binary. It is 111001 (bin). Then convert 23(dec) and it is 10111 (bin). (dec) for decimal and (bin) for binary. Write both these down by maintaining positions. I used to do two things here. Write in groups of 4 bits together (as b-bits represent one char of HEX, forget about this if you don't know that for now). Fill zeros until the number is a group of 4 bits.
0011 1001 (bin)
0001 0111 (bin) OR
------------------------
Now lets apply the truth table for each bit position (this is called bit wise operation).
0011 1111 (bin) = 63 (dec).
Not lets go to your example.
Here num1 = 1, num2 = 2
Convert these to binary.
num1 = 0001 (bin)
num2 = 0010 (bin)
num1 OR num2 is denoted by ( num1 | num2) in Java
0001 (bin)
0010 (bin) OR
------------
0011 (bin) = 3 (dec)
========
Re: Help for this.
yeah bro i got the idea.Thank you for the help.I have little knowledge about Boolean algebra from physics.I had some lessons in AL physics subject.^ is the bitwise XOR operator.
The result of (x > y) is either 0 or 1. If x > y, the output of (x > y) is 1.
If x <= y {that is NOT (x > y) }, the result of (x > y) is 0.
So you now understand that (x > y) outputs either 0 or 1.
Lets take the other part (num1 != num2).
This of cause outputs either 0 or 1. If num1 not equals to num2, it outputs 1. Else (that is num1 == num2) it outputs 0.
Say (x > y) is A and (num1 != num2) is B. Then we have A ^ B.
The truth table of XOR is below.
The main problem is JAVA symbols are new to me.so i think the problem with the symbol knowledge in me.I am keep studding on that.
Re: Help for this.
thank you for the wiki link you gave me.some fact are new to me on that page & some were in my knowledge.
I learn from you explanation you gave me about (1|2)..you are a good teacher NEO bro.
we can use 4digits 1-->15.....the biggest number that we can represent by 4 digits is 15..right? by 1111(binary)
If we need to convert the number over 15 we have to get another 4 digits code like this. 0010 0011...
(please tell me if I am wrong..)
Thank you again...
I learn from you explanation you gave me about (1|2)..you are a good teacher NEO bro.
we can use 4digits 1-->15.....the biggest number that we can represent by 4 digits is 15..right? by 1111(binary)
If we need to convert the number over 15 we have to get another 4 digits code like this. 0010 0011...
(please tell me if I am wrong..)
I got the idea from this example.num1 OR num2 is denoted by ( num1 | num2) in Java
0001 (bin)
0010 (bin) OR
------------
0011 (bin) = 3 (dec)
========
Thank you again...
Re: Help for this.
Not quite clear. However the point is since 4 binary digits represent numbers from 0 to 15 (as you said too), we can easily convert a binary number to Hex.G-sparkZ wrote:we can use 4digits 1-->15.....the biggest number that we can represent by 4 digits is 15..right? by 1111(binary)
If we need to convert the number over 15 we have to get another 4 digits code like this. 0010 0011...
(please tell me if I am wrong..)
Say we have a 8 digit binary number 1011 1101 (bin) and we need to convert it to Hex (base 16). Then we convert 1011 (bin) to Hex and write it as the at left side. 1011 (bin) = 11 (dec) = B (hex). Then we convert 1101 (bin). It is 13 (dec) and D (hex). So the conversion of the binary number to hex is BD (hex). Hex is usually written as 0xBD.
Hope you get the idea.
Re: Help for this.
yeah bro..thanks for the help..now I am with that calculator problem....