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

Mock exam dout on JavaRanch regarding shift operator

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q)
What will the sign of x be after x>>2?
Ans)negative How


Ans)0000 10101 How?
Please explain there answers
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For the first bit pattern 1011 0001
note that this is a negative number and we are doing a signed right shift. In a signed right shift, we replace the MSBs(most significant bits whch are the leftmost bits) by the sign bit

so 1011 0001 >> 2
step1:_ _ 10 1100 // shift to right by 2
step2:1110 1100 // fill MSBs with sign bit which is one here

1110 1100 is a negative no because of 1 in the MSB.

-------------------------------------------------------------------

For the bit pattern 0010 0001

I think the answer should be 0000 1000 and not 0000 10101
 
author
Posts: 119
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shifting isn't covered in the 5.0 exam. Check out objective 7.6, which lists all the operators you need to know about.

-- Phil
 
We should throw him a surprise party. It will cheer him up. We can use this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic