Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!wuarchive!zaphod.mps.ohio-state.edu!math.lsa.umich.edu!sharkey!indetech!pacbell!barn!everexn!roger From: roger@everexn.com (Roger House) Newsgroups: comp.lang.c Subject: Re: Help!!!! Message-ID: <1990Sep21.182142.9013@everexn.com> Date: 21 Sep 90 18:21:42 GMT References: <26f8528c.35c1@uop.uop.edu> Organization: Everex Systems, Inc. Lines: 27 In <26f8528c.35c1@uop.uop.edu> acs17111@uop.edu (hamid misnan) writes: >Hai, > Can someone help me in how can I swap bit 2 and 5, I had tried > to use bitwise, but I cannot finger it out how it will work. > Any help will be appreciated. > Thanks in advance. The possible transformations are these: 543210 ---------------------- 0xx0xx -> no change 0xx1xx -> 1xx0xx 1xx0xx -> 0xx1xx 1xx1xx -> no change Say B is the variable for which bits 2 and 5 are to be swapped. Then this code will do the trick, although it requires the use of another variable, t: if ((t = B & 0x24) && t != 0x24) /* Swap bits 2 and 5 of B */ B ^= 0x24; There are probably better ways to do it. Roger House