Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!usenet.ins.cwru.edu!abvax!iccgcc!browns From: browns@iccgcc.decnet.ab.com (Stan Brown, Oak Road Systems) Newsgroups: comp.lang.c Subject: Re: Help!!!! Message-ID: <1046.26f8c3ef@iccgcc.decnet.ab.com> Date: 20 Sep 90 18:28:14 GMT References: <26f8528c.35c1@uop.uop.edu> Lines: 26 In article <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. sometype swap_bits_2and5(sometype mumble) { sometype bit2, bit5; bit2 = mumble & (sometype)0x04; bit5 = mumble & (sometype)0x20; return (mumble ^ (bit2|bit5)) | (bit2<<3) | (bit5>>3); } Depending on the actual type of the value, some of those casts may not be necessary. And now, inquiring minds want to know: Why on earth do you want to do this? -- Stan Brown, Oak Road Systems, Cleveland, Ohio, U.S.A. (216) 371-0043 Disclaimer: Your mileage may vary. Close cover before striking. Void where taxed, regulated, licensed, or prohibited by law. I am not a crook.