• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Need help on Shift operators

 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello Everybody,
I had been to one interview. There were few questions about shift operator.
1)what is the value of 4>>>5(not sure whether it is <<< or >>> . I know that >>> stands for XOR operation. 4=0100, 5=0101. xor for these is 9=1011.
But, i came to know that the answer is wrong.

Can any one help in solving this problem? what is the value of 4>>>5?
Also, what is the value of 2>>3? what are the steps to solve about two problems?
Please guide me??

Regards,
 
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

1)what is the value of 4>>>5(not sure whether it is <<< or >>> . I know that >>> stands for XOR operation. 4=0100, 5=0101. xor for these is 9=1011.
But, i came to know that the answer is wrong.



First, ">>>" is *not* an XOR operation. It is an unsigned shift right.

Second, assuming that it is an XOR operation, how did you get a 9 from the xor of 4 and 5?

Henry
 
Henry Wong
author
Posts: 23958
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, forgot to answer the question(s)...

- Unsigned Shift Right of the value of 4 by 5 is 0.

- The XOR of the values of 4 and 5 is 1.

Henry
 
Anu satya
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Henrry for the answer.
Sorry, i asked wrong question. ^ stands for xor operator.

Can you please explain me how shift operators work? or any link to refer??

regards,
 
Anu satya
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I wanted to ask one more question: is 4^5 is equivalent of 4 to the power of 5 or 2 to the power of 4 or 2 to the power of 5 or 2 to the power of (4+5)???
Any equivalent form in term of exponential??? There was a question in the written test. I am not finding answer for it.....

any help will be appreciated.

Reagrds
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
^ is exclusive or.

So 4 ^ 5 = 100 ^ 101 = 001.

There is no exponential operator in Java.

There is a method pow in java.lang.Math that you can use to raise a number to a power.
[ June 05, 2006: Message edited by: Keith Lynn ]
 
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read Cat and Mouse Game with Bits
 
roses are red, violets are blue. Some poems rhyme and some are a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic