• Post Reply Bookmark Topic Watch Topic
  • New Topic

Binary Inversion Operator(~)  RSS feed

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..

What gets printed when the following program is compiled and run. Select the one correct answer and provide the clarification please...


public class test {
public static void main(String args[]) {
byte x = 3;
x = (byte)~x;
System.out.println(x);
}
}


1. 3
2. 0
3. 1
4. 11
5. 252
6. 214
7. 124
8. -4

Source:This question was asked in a Java Mock test on net.
 
Sheriff
Posts: 9610
37
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Priya, welcome to javaranch.

First of all this type of question will not be asked in SCJP. They were removed from SCJP 1.5 and are not in SCJP 1.6. So you don't need to worry about it.

Secondly if you post a question from somewhere, you must disclose from where you copied the question. So keep this in mind while asking questions you must tell the source from where you copied the question.

Also please don't use unnecessary formatting like you have done by making your whole post bold. I hope that you won't feel bombarded with rules
 
Priya Jaspal
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ankit,

I have done editing with my post.
Hope its fine now...If still there is any problem then please let me know.

I know this type of question will not be asked in SCJP1.5.
But i found it somewhere.
I know the answer but wondering on it.
I will be grateful if it will be answered.
 
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Now you need to know how to calculate 1100.
 
Priya Jaspal
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know that 1100 is 12 in decimal number system.
But 12 is not at all there in options.

So,Can you be more clear?

 
Punit Singh
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Priya Jaspal wrote:I know that 1100 is 12 in decimal number system.
But 12 is not at all there in options.

So,Can you be more clear?



actually it is:



Now try.
 
Priya Jaspal
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah...Now I understood.

-4 will be the correct answer.

Thanks a lots!
 
Java Cowboy
Sheriff
Posts: 16078
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Priya Jaspal wrote:Source:This question was asked in a Java Mock test on net.


Please quote your sources properly.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!