Big Moose Saloon
 Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies Register / Login

# Shift Operators

rashu gulati
Greenhorn

Joined: Nov 06, 2003
Posts: 12
Hi
I need to know the answer of : -42>>-4 and also a easy way to find it out.
Also Can shift operators be applied to float,double.
Thanks
Rashu Gulati
Bert Bates
author
Sheriff

Joined: Oct 14, 2002
Posts: 8898

5
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

Spot false dilemmas now, ask me how!
(If you're not on the edge, you're taking up too much room.)
rashu gulati
Greenhorn

Joined: Nov 06, 2003
Posts: 12
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

Joined: Oct 14, 2002
Posts: 8898

5
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

Joined: Oct 14, 2002
Posts: 8898

5
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!

I agree. Here's the link: http://aspose.com/file-tools

subject: Shift Operators