Jul 26, 2005 #1 H hegazyelm3lm Newbie level 1 Joined Jul 26, 2005 Messages 1 Helped 0 Reputation 0 Reaction score 0 Trophy points 1,281 Activity points 1,288 rotating variables in C Hi i am using CodeVisionAVR i want to rotate 8-bit variables, can anyone help me?
rotating variables in C Hi i am using CodeVisionAVR i want to rotate 8-bit variables, can anyone help me?
Jul 26, 2005 #2 A asahin11 Member level 3 Joined Jun 20, 2005 Messages 57 Helped 3 Reputation 6 Reaction score 0 Trophy points 1,286 Activity points 1,767 Re: rotating variables in C hi hegazyelm3lm, I dont know CodeVisionAVR but on C you can use << or >> operator to rotate left or right. For example; i << 1 : rotate i to left one bit i >> 2 : rotate i to right two bit regrads,
Re: rotating variables in C hi hegazyelm3lm, I dont know CodeVisionAVR but on C you can use << or >> operator to rotate left or right. For example; i << 1 : rotate i to left one bit i >> 2 : rotate i to right two bit regrads,
Jul 26, 2005 #3 R Rooftop Full Member level 2 Joined Oct 28, 2004 Messages 134 Helped 4 Reputation 8 Reaction score 2 Trophy points 1,298 Activity points 1,241 Re: rotating variables in C hi all, Emm i'm not sure but isn't >> just shift, not rotate? I'm using keill and if i write a = a >> 1; then it means a will be shifted to right once and if i write a = a << 2; then it means a will be shifted to left twice. I dunno it's different or not but in Keill it's just shift not rotate Anyway i'm looking for how to rotate right or left too That's all thanks a lot
Re: rotating variables in C hi all, Emm i'm not sure but isn't >> just shift, not rotate? I'm using keill and if i write a = a >> 1; then it means a will be shifted to right once and if i write a = a << 2; then it means a will be shifted to left twice. I dunno it's different or not but in Keill it's just shift not rotate Anyway i'm looking for how to rotate right or left too That's all thanks a lot
Jul 26, 2005 #4 checkmate Advanced Member level 3 Joined Feb 25, 2004 Messages 832 Helped 178 Reputation 356 Reaction score 125 Trophy points 1,323 Location Toilet Seat Activity points 7,811 Re: rotating variables in C The <</>> are shift operators, not rotate operators. This applies on all variants of C I have ever come across. In C, you can do this new=(old & 0x01)?((old>>1) | 0x80)old>>1) I'm not an AVR user, but I'm pretty sure that they have rotate in their ISA. Then the optimal method is to do an inline ASM.
Re: rotating variables in C The <</>> are shift operators, not rotate operators. This applies on all variants of C I have ever come across. In C, you can do this new=(old & 0x01)?((old>>1) | 0x80)old>>1) I'm not an AVR user, but I'm pretty sure that they have rotate in their ISA. Then the optimal method is to do an inline ASM.
May 16, 2010 #5 A amrstaha Full Member level 2 Joined Aug 29, 2005 Messages 136 Helped 8 Reputation 16 Reaction score 2 Trophy points 1,298 Location Egypt Activity points 2,312 Try this: x=(x<<1)|(x>>7); this will rotate the byte x one bit position to the left. x=(x>>1)|(x<<7); and this will rotate it to the right. Good luck.
Try this: x=(x<<1)|(x>>7); this will rotate the byte x one bit position to the left. x=(x>>1)|(x<<7); and this will rotate it to the right. Good luck.