If you are doing it one bit at a time, use this: xxx=3Dyyy<<1+xxx; For 8 bits at a time, use this: xxx=3Dyyy<<8+xxx; Of course, to shift right, use the oppposit shift=20 direction. Ray On 27 Aug 2015 at 10:10, Josh Koffman wrote: From: Josh Koffman=20 Date sent: Thu, 27 Aug 2015 10:10:05=20 -0400 Subject: [PIC] XC8 Bit Technique? To: "Microcontroller discussion=20 list - Public." Send reply to: "Microcontroller discussion=20 list - Public." =09 =09 > Hi all, >=20 > Amongst all the other things on my plate right now, I'd like to make > a > small library to do Bit Angle Modulation on some of my projects. I > made one years ago in assembly, but now I'd like to do it in XC8. >=20 > For reference, there are some great posts on BAM on the PicBasic > forums here: >=20 > http://www.picbasic.co.uk/forum/showthread.php?p=3D45597 > http://www.picbasic.co.uk/forum/showthread.php?t=3D10564 >=20 > Because the PIC will be doing many things, I am considering using > a > high priority interrupt for the BAM, but keeping my high priority > ISR > as small as possible (which is probably a good idea regardless). > To > accomplish this, I want to create the 8 "slices" that I will output > in > my main line, so that all the BAM ISR has to do is take that > variable > and put it on the port. >=20 > My question is, what would be the best way to handle this in C? When > I > did it in assembly I used a rotate (rotate right if I remember > correctly), then read the carry bit. But then I was also doing it > at > the moment of outputting, so there was no intermediate stored > variable. >=20 > My current thought is to define a typedef that lets me access the > individual bits, then a bunch of if/else statements that check the > bit > of the source value, and if it's a 1 set the bit of the > corresponding > "slice" variable. This would result in a lot of if statements > though, > so I'm wondering if there's a slicker way to do this. >=20 > I'm trying to avoid dropping into ASM to do this for a few > reasons. >=20 > Any thoughts? >=20 > Thanks! >=20 > Josh > --=20 > A common mistake that people make when trying to design something > completely foolproof is to underestimate the ingenuity of complete > fools. > -Douglas Adams > --=20 > http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive > View/change your membership options at > http://mailman.mit.edu/mailman/listinfo/piclist --=20 http://www.piclist.com/techref/piclist PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .