• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Binary Inversion Operator(~)

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 9707
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah...Now I understood.

-4 will be the correct answer.

Thanks a lots!
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic