: : : : Hi Friends,
: : : :
: : : : Plz send me the code to swap two bits of byte data ,
: : : : Waiting for positive reply,
: : : :
: : : : Ex: Before: 0x80
: : : : After : 0x01
: : : :
: : : : Rajesh
: : :
: : : Pseudocode:
: : : - Get the byte
: : : - Get the two bits
: : : - Swap the two bits
: : : - Put the bits back in the byte
: : :
: : : You can do without bithsifting, but perhaps this page give some inspiration:
: : :
http://www.codepedia.com/1/CppBitShifting
: : :
: : : See ya and good luck,
: : : bilderbikkel
: : :
: : :
: :
: :
: : I don't see how you could do it without shifting in an effective way.
: : I would write it in assembler myself, since this is a typical algorithm where assembler is much more efficient - you don't have rotate and check carry in C/C++.
: :
: :
:
Why check anything? Simply mask out the unneeded bits and then shift both values and then clear the old bit values and then OR them with the values from previoud shift.
:
I'm assuming he wants a generic "mirror" algorithm, ie 0xAAAA would be translated to 0x5555. Otherwise the source code I first posted would do fine as well...