# Why is this output?

- 0

Please explain me why and HOW is it printing the o/p like it does below?

**int result = 2 ^ 3 //prints 1**

int result = 3 ^ 3 //prints 0

int result = 3 ^ 77 //prints 78 ???

int result = 3 ^ 3 //prints 0

int result = 3 ^ 77 //prints 78 ???

Thanks,

Jothi Shankar Kumar. S

SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master

Did a rm -R / to find out that I lost my entire Linux installation!

- 0

Thanks for the reply. But how did you know that 2 is represented as 000000000000......10 in binary form? I just wanna know that.

Regards,

Jothi Shankar Kumar. S

SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master

Did a rm -R / to find out that I lost my entire Linux installation!

- 0

And Int is 32 bit in Java.

[ October 11, 2006: Message edited by: Tim LeMaster ]

- 0

Will the SCJP exam require us to know all this? I'm planning for SCJP 1.4. Will this do any good to me to know in depth about this?

Regards,

Jothi Shankar Kumar. S

SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master

Did a rm -R / to find out that I lost my entire Linux installation!

- 0

Originally posted by Jothi Shankar Kumar Sankararaj:

Hi Guys,

Thanks for the reply. But how did you know that 2 is represented as 000000000000......10 in binary form? I just wanna know that.

Regards,

Jothi Shankar Kumar. S

Binary form is represented (with no surprise) with base 2 mathematics. See this for more information.

Henry

- 0

Thanks for those who helped me with this. Is there any hard and fast rule with which we can convert decimal numbers to binary?? Anyone on this?

Regards,

Jothi Shankar Kumar. S

Did a rm -R / to find out that I lost my entire Linux installation!

- 0

Jothi Shankar Kumar Sankararaj wrote:

Is there any hard and fast rule with which we can convert decimal numbers to binary??

What do you mean by decimal numbers?

If you mean integers to the base 10, then try e.g.

If you mean floating point numbers (doubles and floats) than the answer is no.

They are treated with different precission, depending your methods or classes have the strictfp modifier or not.

Yours,

bu.

all events occur in real time

- 0

Tha above explanation is fine but I wont have the chance to compile when I write my exam??javascript: x()

Big Grin

The above explanation is fine but what if I want to try it out in a paper when I find similiar question on the exam? I remember learing binary to decimal conversion in my school days. So anyone please let me know the logic behind the conversion.

Regards,

Jothi Shankar Kumar. S

Did a rm -R / to find out that I lost my entire Linux installation!

- 0

Thanks for the reply. That link really helped me.

Regards,

Jothi Shankar Kumar. S

Did a rm -R / to find out that I lost my entire Linux installation!

It is sorta covered in the JavaRanch Style Guide. |