File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes  operator Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark " operator" Watch " operator" New topic


Nikos Stavros
Ranch Hand

Joined: Feb 24, 2006
Posts: 243

could someone tell me what is going on here with these << tags

Jesus lives
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
They're not "tags", they're "operators". Anyway...

The << operator is being used to create integers that are various powers of two. If you take the integer 1, then that's 2 to the power zero. If you bit-shift it once to the left, you get 2, which is 2 to the power 1. Shift again, you get 4, which is 2 to the power 2 etc.

The original developer could easily just have written the constants 1, 2, 4 etc. The reason for the more complicated way of writing it is probably to make it clear that these are all powers of two. They are, in fact, probably bit-masks for a value that's a bitset of flags.

(later) ... although actually it looks like the values are all different ways of opening some resource. They sound as if they're probably mutally-exclusive. In which case, use bit-masks, bitsets etc. is probably overkill. You might be able to accuse the original developer of being a smart-arse.
[ April 24, 2006: Message edited by: Peter Chase ]

Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Nikos Stavros
Ranch Hand

Joined: Feb 24, 2006
Posts: 243

thanks for clearing that up for me. its easy to forget the underlying binary format of ints
I agree. Here's the link:
subject: operator
It's not a secret anymore!