Thread: Bit transposing

  1. #1
    Registered User
    Join Date
    Nov 2003

    Bit transposing

    i was wondering on how to do a bit transposition.
    I really need this for a project i am doing encrypting a data base.
    and i am stumped on this one.
    all help is appreciated

  2. #2
    mustang benny bennyandthejets's Avatar
    Join Date
    Jul 2002
    You can determine whether or not a particular bit is turned on by using the & operator, ie:
    if (value & 0x01)
    if (value & 0x02)
    if (value & 0x04)
    if (value & pow(2,0))
    if (value & pow(2,1))
    if (value & pow(2,2))
    To ensure a bit is turned on, do this:
    To ensure it is off, do this:
    Note that those last two code pieces will ensure the bit state no matter what it was orginally, so they're safe to use without first checking the state.

    I suggest a function signature like this:
    int SwapBits(int value, int index1,int index2);
    Good luck. Have a shot, then post any problems you have.
    Microsoft Visual Studio .NET 2003 Enterprise Architect
    Windows XP Pro

    Code Tags
    Programming FAQ

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 11-10-2005, 10:53 AM
  2. porting application from 32 bit to 64 bit error
    By gandalf_bar in forum Linux Programming
    Replies: 1
    Last Post: 09-14-2005, 09:20 AM
  3. Bit processing in C
    By eliomancini in forum C Programming
    Replies: 8
    Last Post: 06-07-2005, 10:54 AM
  4. Bit Manipulation Questions
    By CPPNewbie in forum C++ Programming
    Replies: 7
    Last Post: 08-12-2003, 02:17 PM
  5. Array of boolean
    By DMaxJ in forum C++ Programming
    Replies: 11
    Last Post: 10-25-2001, 11:45 PM