Thread: switch case

  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    2

    switch case

    Hello,

    I'm altering a code witch contains the following:

    switch (variable>>8)

    The problem is that the switch only contains case 0 to 5 and default. Can anyone explain what ">>" means is this case, I can't seem to find it on the internet.

    (The code compiles and the program works.)

    Thanks!

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Consult your operator precedence table.

    Here's one...
    C Operator Precedence Table
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Tiemer View Post
    Hello,

    I'm altering a code witch contains the following:

    switch (variable>>8)

    The problem is that the switch only contains case 0 to 5 and default. Can anyone explain what ">>" means is this case, I can't seem to find it on the internet.

    (The code compiles and the program works.)

    Thanks!
    It's the functional equivalent of variable /= 256;

  4. #4
    Registered User
    Join Date
    Apr 2011
    Posts
    2
    Thank you both for the quick answers!

  5. #5
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Tiemer View Post
    I appreciate your comment but I still can't figure out what this command does. Is it that the 16 bit variable becomes a 8 bit variable witch contains the highest 8 bits of the original value?
    Ok... original value 00000111 01111111 now we bit shift it 8 places right (>> 8) and we get 00000000 00000111 (assuming the original value was unsigned and/or non-negative)

    It's a way of accessing the high byte of a word...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 08-25-2008, 12:01 PM
  2. Switch and Case
    By ednnd in forum C Programming
    Replies: 12
    Last Post: 10-07-2005, 09:46 PM
  3. switch, case help
    By campermama in forum C++ Programming
    Replies: 7
    Last Post: 06-16-2004, 09:49 AM
  4. Switch Case
    By FromHolland in forum C++ Programming
    Replies: 7
    Last Post: 06-13-2003, 03:51 AM
  5. Switch/Case using && != and ||?
    By Kespoosh in forum C++ Programming
    Replies: 6
    Last Post: 03-15-2003, 11:24 PM