Thread: Bitwise rotate array

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #6
    Registered User
    Join Date
    Jan 2013
    Posts
    106
    Yes, but looking at the results further,
    it doesn't look like the original function carries the bit that drops off the left,
    and feeds it into the right of the array, so it's not exactly what I'm after.
    If you rotate it enough, the array will end up all zeros.

    EDIT,,

    this is the big rotate I really wanted (shift left though), but I didn't do it.

    Code:
    void shiftl(void *object, size_t size) {
        
        unsigned char *byte;
        
        byte = object;  // NEW
        unsigned char leftbit = byte[1] & (1 << (CHAR_BIT - 1)) ? 1 : 0;   // NEW
        for ( byte = object; size--; ++byte ) {
            
            
            unsigned char bit = 0;
            if ( size ) {
    
    
                bit = byte[1] & (1 << (CHAR_BIT - 1)) ? 1 : 0;
            }
            else {
                bit = leftbit;  // NEW
            }  // NEW
            *byte <<= 1;
            *byte  |= bit;
        }
    }
    Last edited by xArt; 01-23-2013 at 09:39 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Rotate char array
    By pascalbb in forum C++ Programming
    Replies: 8
    Last Post: 10-18-2006, 10:26 AM
  2. Do I really need to rotate?
    By JimJoyce in forum Game Programming
    Replies: 13
    Last Post: 02-24-2005, 04:04 PM
  3. How to rotate
    By cfrost in forum Windows Programming
    Replies: 5
    Last Post: 07-15-2004, 10:08 AM
  4. how to rotate url randomly?
    By Antipher in forum Tech Board
    Replies: 3
    Last Post: 03-21-2003, 02:34 AM
  5. How Do you rotate a multidimensional array?
    By werdy666 in forum C++ Programming
    Replies: 3
    Last Post: 09-29-2002, 10:03 AM