• 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
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

bit shiftting pblm

 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
please expalin me how to slove following pblm

-4 >> 34

-4 >>> -34

thanks in advance
sunitha
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It goes like this :
If you have a +ve number and every time you shift rightgives you a number equivalent to integer division by 2.
ie 4 >> 1 gives(4/2)ie 2, 4 >> 2 gives(4/4) ie 1.

if you do it 32 times right shift gives you the same number ie 4.
ie any multiple of 32(0, 32, 64, 128) also gives you the same number ie 4.

Any number(say n ) above 32, 64, 128..... times shifting gives you (n-32) times right shift.

So 33 means shift (33-32) ie 1. equivalent 4 >> 33 is 4 >> 1.
So 34 means shift (34-32) ie 2. equivalent 4 >> 34 is 4 >> 2.

Simillarly in case of -ve numbers, the sign bit is always 1 and it is stored as 2's complement form.

So shifting more than 2 times -4 ( ie -4 >> 3 ) gives you -1(not zero). other rules being same.
ie -4 >> 32 = -4
-4 >> 64 = -4
-4 >> 33 is -4 >> 1 = -2

not sure about >>> ???
 
Ranch Hand
Posts: 1277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
does the exam expects shifting such weird integers
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Niranjan Deshpande:
does the exam expects shifting such weird integers



AFAIK there is no shifting in 5.0. In 1.4 you probably may meet such stuff.
 
We've gotta get close enough to that helmet to pull the choke on it's engine and flood his mind! Or, we could just read this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic