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.

How to Rotate byte programming in C

Status
Not open for further replies.

8051HELP

Member level 1
Joined
Nov 27, 2015
Messages
32
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
251
Hi.

I need to rotate for an example x=0XFF for 3 to right.

I cant do that only with >> because that is shifting.
When you want rotate you need to "memory" all bit not to lose such as in case for shifting (i think).
So that is not the same.

Can I use this (x & 0xFF)>>3 ; for rotate ??
 

With a quick search on the web, we can find this opperation, also called as circular shift.
The following video shows an implementation.


At this website, there is an inline implementation for 32 bit variables:
Code:
y = (x<<n) | (x>>(32-n));

I would dare to say that we could perhaps infer a more generic expression for any type ( not tested ! ):
Code:
y = (x<<n) | (x>>(sizeof(x)-n));
 

O.K.

So may do like this

Code:
(x>>3) | (x<<( (-3) & 0xFF ));
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top