Two Laptop Bag
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Binary Inversion Operator(~) Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "Binary Inversion Operator(~)" Watch "Binary Inversion Operator(~)" New topic
Author

Binary Inversion Operator(~)

Priya Jaspal
Greenhorn

Joined: Jan 29, 2009
Posts: 5
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.
Ankit Garg
Saloon Keeper

Joined: Aug 03, 2008
Posts: 9189
    
    2

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


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Priya Jaspal
Greenhorn

Joined: Jan 29, 2009
Posts: 5
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.
Punit Singh
Ranch Hand

Joined: Oct 16, 2008
Posts: 952


Now you need to know how to calculate 1100.


SCJP 6
Priya Jaspal
Greenhorn

Joined: Jan 29, 2009
Posts: 5
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

Joined: Oct 16, 2008
Posts: 952
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

Joined: Jan 29, 2009
Posts: 5
Yeah...Now I understood.

-4 will be the correct answer.

Thanks a lots!
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12929
    
    3

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

Please quote your sources properly.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Binary Inversion Operator(~)
 
Similar Threads
assigning boolean to integer.
shift opeartors - need help
well a doubt !
Bitwise inversion operator question
Abt bitwise complement operator!