shift operator << and >> question...

Discussion in 'C++' started by Peter Lee, Mar 11, 2007.

  1. Peter Lee

    Peter Lee Guest

    ASSUME unsigned int = 32 bits

    #q1 unsigned int u1 = 3u << 0u valid?
    #q2 unsigned int u2 = 3u >> 0u valid?
    #q3 unsigned int u3 = 3u << 32u valid?
    #q4 unsigned int u4 = 3u >> 32u valid?
    Peter Lee, Mar 11, 2007
    #1
    1. Advertising

  2. Peter Lee

    peter koch Guest

    On 11 Mar., 13:52, "Peter Lee" <> wrote:
    > ASSUME unsigned int = 32 bits
    >
    > #q1 unsigned int u1 = 3u << 0u valid?
    > #q2 unsigned int u2 = 3u >> 0u valid?

    Yes
    > #q3 unsigned int u3 = 3u << 32u valid?
    > #q4 unsigned int u4 = 3u >> 32u valid?

    No - you are only allowed to shift less than the bits in the type. So
    the max is 31 in your case.

    /Peter
    peter koch, Mar 11, 2007
    #2
    1. Advertising

  3. Peter Lee

    Rolf Magnus Guest

    Peter Lee wrote:

    > ASSUME unsigned int = 32 bits
    >
    > #q1 unsigned int u1 = 3u << 0u valid?


    yes

    > #q2 unsigned int u2 = 3u >> 0u valid?


    yes

    > #q3 unsigned int u3 = 3u << 32u valid?


    no

    > #q4 unsigned int u4 = 3u >> 32u valid?


    no
    Rolf Magnus, Mar 11, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Roberto Gallo

    Shift - byte[] buf shift

    Roberto Gallo, Jan 27, 2004, in forum: Java
    Replies:
    3
    Views:
    2,049
    Thomas Schodt
    Jan 27, 2004
  2. Wenjie
    Replies:
    3
    Views:
    1,037
    Ron Samuel Klatchko
    Jul 11, 2003
  3. Santosh Nayak

    Left Shift / Right Shift Operators

    Santosh Nayak, Nov 30, 2006, in forum: C Programming
    Replies:
    16
    Views:
    1,450
    CBFalconer
    Nov 30, 2006
  4. Sanny
    Replies:
    38
    Views:
    3,398
    Thomas Richter
    Apr 29, 2011
  5. devphylosoff

    what "shift" does, if not "$_ = shift;" ?

    devphylosoff, Nov 29, 2007, in forum: Perl Misc
    Replies:
    3
    Views:
    326
    Michele Dondi
    Dec 4, 2007
Loading...

Share This Page