• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Shift Operators

 
rashu gulati
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
I need to know the answer of : -42>>-4 and also a easy way to find it out.
Please help me
Also Can shift operators be applied to float,double.
Thanks
Rashu Gulati
 
Bert Bates
author
Sheriff
Posts: 8900
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey Rashu,
Tell us what you already know about shift operators, and this particular question...
Are the operands ints or longs? Does it make a difference? What do you think the rules for floats and doubles are?
Bert
 
rashu gulati
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that the left operand can be promoted to long or int.
Also i know something abt. <<,<<< & >> operators but cant really figure out a way to solve when some negative numbers come into picture.
Thanks
 
Bert Bates
author
Sheriff
Posts: 8900
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rashu -
Good start! So I'd start out with some easier tests like:
42 >> 1
-42 >> 1
-42 >> -1
See what results you get...
My hint is, get out your pencil and paper, and write down the bit patterns of the before and afters, and see what you can figure out. For the real exam, you'll have to understand two's complement when you're figuring out these bit-shifting questions, so this is a great place to start!
 
Bert Bates
author
Sheriff
Posts: 8900
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rashu -
Good start! So I'd start out with some easier tests like:
42 >> 1
-42 >> 1
-42 >> -1
See what results you get...
My hint is, get out your pencil and paper, and write down the bit patterns of the before and afters, and see what you can figure out. For the real exam, you'll have to understand two's complement when you're figuring out these bit-shifting questions, so this is a great place to start!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic