Hello,
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
thanks
This is a discussion on Bit transposing within the C++ Programming forums, part of the General Programming Boards category; Hello, i was wondering on how to do a bit transposition. I really need this for a project i am ...
Hello,
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
thanks
You can determine whether or not a particular bit is turned on by using the & operator, ie:
To ensure a bit is turned on, do this:Code: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 it is off, do this:Code:value|=0x01;
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.Code:value&=~(0x01);
I suggest a function signature like this:
Good luck. Have a shot, then post any problems you have.Code:int SwapBits(int value, int index1,int index2);
benforbes@optusnet.com.au
Microsoft Visual Studio .NET 2003 Enterprise Architect
Windows XP Pro
Code Tags
Programming FAQ
Tutorials