C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28695
Number of posts: 94715

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Re: How to SWAP 2 Bits in a BYTE Data Posted by Lundin on 20 Sept 2006 at 4:29 AM
: : : : 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...
Thread Tree
Rajesh N How to SWAP 2 Bits in a BYTE Data on 19 Sept 2006 at 4:56 AM
Lundin Re: How to SWAP 2 Bits in a BYTE Data on 19 Sept 2006 at 5:19 AM
Gregry2 Re: How to SWAP 2 Bits in a BYTE Data on 19 Sept 2006 at 5:27 AM
bilderbikkel Re: How to SWAP 2 Bits in a BYTE Data on 19 Sept 2006 at 8:12 AM
Lundin Re: How to SWAP 2 Bits in a BYTE Data on 19 Sept 2006 at 11:41 PM
AsmGuru62 Re: How to SWAP 2 Bits in a BYTE Data on 20 Sept 2006 at 4:08 AM
Lundin Re: How to SWAP 2 Bits in a BYTE Data on 20 Sept 2006 at 4:29 AM
k_v_ashok11 Re: How to SWAP 2 Bits in a BYTE Data on 16 Dec 2008 at 10:53 PM
Lundin This post has been deleted. on 17 Dec 2008 at 5:05 AM



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.