• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

operator

 
Nikos Stavros
Ranch Hand
Posts: 243
Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
could someone tell me what is going on here with these << tags
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Nikos Stavros
Ranch Hand
Posts: 243
Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for clearing that up for me. its easy to forget the underlying binary format of ints
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic