Thread: Shift Operators question

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    7

    Shift Operators question

    How do you set up a right shift or left ........ doing an infinite loop?

    like for example,

    the hex 0x55 which is equal t
    o 0101 0101 in binary

    now i want to shift the value of 0x55 to 1 to the right

    so its
    Code:
    int value;
    value = value >> 1;
    then that changes the binary value to

    0010 1010

    then another shift will make it

    0001 0101

    whats happening here is it is shifting to the right but its not going back to the other side. Im triying to figure out how can i make this code in a loop like:

    1010 0000 = form 1
    0101 0000
    0010 1000
    0001 0100
    0000 1010
    0000 0101
    1000 0010 in here the bit 1 goes back to the other side
    0100 0001
    1010 0000 now its back to form 1

  2. #2
    Registered User
    Join Date
    Nov 2011
    Posts
    161
    Without coding it for you, I would look at the LSb, then shift,
    then OR what was the LSb with the MSb of the shift result.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question re: SSE - shift-right, integer-divide(?)
    By lostpacket in forum C++ Programming
    Replies: 2
    Last Post: 03-08-2010, 10:55 PM
  2. bitwise shift operators in -ve numbers
    By rohit_second in forum C Programming
    Replies: 11
    Last Post: 09-15-2008, 01:18 PM
  3. anyone help with this shift bit question
    By movl0x1 in forum C Programming
    Replies: 12
    Last Post: 05-18-2007, 11:38 AM
  4. Shift operators in C
    By jedi_jinn in forum C Programming
    Replies: 4
    Last Post: 10-23-2006, 02:52 AM
  5. Question about operators.
    By Liger86 in forum C++ Programming
    Replies: 3
    Last Post: 12-30-2002, 04:00 PM