Thread: Shift operator doubt

  1. #1
    Registered User
    Join Date
    Mar 2011
    Location
    India ,Kerala
    Posts
    37

    Shift operator doubt

    byte[i] <<= 1; what does it mean ?

  2. #2
    Registered User
    Join Date
    Feb 2012
    Posts
    347
    if you have the complete program it is easy to explain but generally << means left shift example 1 << 2 means 1 in binary 00000001 << 2 gives 00000100 equal to 4.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    You probably have encountered something like this before, i.e., you probably know that this:
    Code:
    x += y;
    is a "short hand" for:
    Code:
    x = x + y;
    Likewise, this:
    Code:
    byte[i] <<= 1;
    has the same net effect as:
    Code:
    byte[i] = byte[i] << 1;
    except that byte[i] is not evaluated twice, which could be important if the expression was:
    Code:
    byte[compute_i()] <<= 1;
    where compute_i might be computationally expensive.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    a <<= b means a = a << b
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Left Shift Operator Over Loading <<
    By nickman in forum C++ Programming
    Replies: 8
    Last Post: 09-01-2014, 03:47 AM
  2. Bitwise Operator Shift
    By YannB in forum C Programming
    Replies: 14
    Last Post: 03-04-2014, 09:49 PM
  3. unsigned right shift operator
    By abraham2119 in forum C Programming
    Replies: 2
    Last Post: 06-05-2009, 11:01 AM
  4. utility of left and right shift operator
    By bhagwat_maimt in forum C++ Programming
    Replies: 8
    Last Post: 12-12-2006, 10:36 PM
  5. left shift operator!!!!
    By theblackhat in forum C Programming
    Replies: 2
    Last Post: 10-02-2004, 02:07 AM