• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

operator

 
Ranch Hand
Posts: 243
Python
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
could someone tell me what is going on here with these << tags
 
Ranch Hand
Posts: 1970
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for clearing that up for me. its easy to forget the underlying binary format of ints
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic