Circular Bit Shifts

This is a discussion on Circular Bit Shifts within the C++ Programming forums, part of the General Programming Boards category; Is it possible to do a circular bit shift in c++? i.e: 10001000 => 00010001 => 00100010 => 01000100 ~Inquirer...

  1. #1
    Rebooted Inquirer's Avatar
    Join Date
    Apr 2002
    Posts
    281

    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, 11:54 AM
  2. Bit shifts
    By Buckshot in forum C++ Programming
    Replies: 13
    Last Post: 05-23-2005, 09: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-26-2001, 12:45 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21