Raphi Houri wrote: > > ---------- > > From: Alan King > > To: PICLIST@MITVMA.MIT.EDU > > Subject: Re: reversing bits > > Date: Saturday, April 12, 1997 1:40 AM > > > > Tony Matthews wrote: > > > > > > Is there a simple (short) way to reverse the order of bits in a byte. > > > or even better a nibble in the middle of a byte ? Thanks > > > > > > Clear carry, > > Rotate left out of in byte (or right) > > Rotate right into out byte (or left) > > Repeat 8 times. What went out of first byte goes into other side > > of second. Actually, you don't have to clear the carry even.. > > > > By the time you get done with it, the 16 inline instructions to rotl, > > rotr,rotl,rotr, & etc won't be much more than setting up a counter and > > looping 8 times, and won't use ram or destroy anything.. > > > > Alan > > Let's get back to basics > > exclusive OR truth table: > > a b f(a,b) > ----------------- > 0 0 | 0 > 0 1 | 1 > 1 0 | 1 > 1 1 | 0 > > >From the table, if you EOR a byte with all 1s you will get all the bytes > inverted. > You may also invert selected bits. > example code: > > (W=%11001001) EOR (%11111111) = %00110110 > > 16c84 code: > XORLW 0xff > > Boolean algebra is beautiful! Agreed but I wanted to reverse the order of bits not invert them and I have gotten several good ideas thanks to all who replied. Tony M. > Raphi Houri > rhouri@pacbell.net