Thread: Circular Bit Shifts

  1. #1

    Circular Bit Shifts

    Is it possible to do a circular bit shift in c++?

    i.e:
    10001000 => 00010001 => 00100010 => 01000100

    ~Inquirer
    Compilers:
    GCC on Red Hat 8.1 (Primary)
    GCC on Mac OS X 10.2.4 (Secondary)

    Others:
    MinGW on XP

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Code:
    char RotateLeft(char Byte)
    {
       return (char)((Byte << 1) | (Byte >> 7));
    }
    I believe there is a "rotate" asm instruction that does this too...
    Not sure if a C/C++ function does it though.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Comment your source code! Lynux-Penguin's Avatar
    Join Date
    Apr 2002
    Posts
    533
    not by any standard means, you could write a class to handle binary numbers and do it yourself. Or write a function that does a circular bit shift.

    -LC
    Asking the right question is sometimes more important than knowing the answer.
    Please read the FAQ
    C Reference Card (A MUST!)
    Pointers and Memory
    The Essentials
    CString lib

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bit processing in C
    By eliomancini in forum C Programming
    Replies: 8
    Last Post: 06-07-2005, 10:54 AM
  2. Bit shifts
    By Buckshot in forum C++ Programming
    Replies: 13
    Last Post: 05-23-2005, 08:14 PM
  3. Porting from 32 bit machine to 64 bit machine!
    By anoopks in forum C Programming
    Replies: 10
    Last Post: 02-25-2005, 08:02 PM
  4. circular shift
    By n00bcodezor in forum C Programming
    Replies: 2
    Last Post: 11-20-2001, 03:51 AM
  5. Array of boolean
    By DMaxJ in forum C++ Programming
    Replies: 11
    Last Post: 10-25-2001, 11:45 PM