Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Rotating 8-bit variables in CodeVisionAVR

Status
Not open for further replies.

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?
 

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 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

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.
 

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.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top