this can be done using the same code as of Sharad above , the only difference being the mask bits , we mask four bits of a nibble by the anding with 0001 , 0010 , 0101 and 1000 .. now , we feed these into the given number .I mean all the bits as below .. Suppose we have a nibble as 1100 and we want it to be 0011 , so after masking , we have the four bits as 1000 , 0100 , 0000 and 0000 respectively .We feed the given bits in a reverse order into a nibble (or a character for that matter ) in a reverse order . So first bit(1000) is shifted right 3 times and added to result , second shifted 1 times and added , third shifted 1 time but to the left and fourth 3 times to the left . we add all of the to have the answer .
On Sun, Jun 13, 2010 at 1:56 PM, jalaj jaiswal <jalaj.jaiswa...@gmail.com>wrote: > can any one explain it using an example... > let say my nibble is 0100... i have to print 0010... in one go using > bitwise operators... > please explain through example > > @ sharad ... your code is to swap two nibbles in a character > > > On Sun, Jun 13, 2010 at 1:39 PM, jaladhi dave <jaladhi.k.d...@gmail.com>wrote: > >> Write a c-macro to use assembly swap opcode. >> >> On Sat, Jun 12, 2010 at 9:35 PM, jalaj jaiswal <jalaj.jaiswa...@gmail.com >> > wrote: >> >>> >>> write an algorithm to reverse a nibble in one pass...using bitwise >>> operators >>> -- >>> With Regards, >>> Jalaj Jaiswal >>> +919026283397 >>> B.TECH IT >>> IIIT ALLAHABAD >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "Algorithm Geeks" group. >>> To post to this group, send email to algoge...@googlegroups.com. >>> To unsubscribe from this group, send email to >>> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> >>> . >>> For more options, visit this group at >>> http://groups.google.com/group/algogeeks?hl=en. >>> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algoge...@googlegroups.com. >> To unsubscribe from this group, send email to >> algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> >> . >> For more options, visit this group at >> http://groups.google.com/group/algogeeks?hl=en. >> > > > > -- > With Regards, > Jalaj Jaiswal > +919026283397 > B.TECH IT > IIIT ALLAHABAD > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.