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.

For Loop with Hex values (Query)

Status
Not open for further replies.

assadmahmood

Junior Member level 3
Junior Member level 3
Joined
Oct 23, 2011
Messages
30
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
Karachi Pakistan
Visit site
Activity points
1,531
Greetings EveryBody!

I have to use a for loop in such a way that its increment should be like this:
0x01
0x02
0x04
0x08
0x10
0x20
0x40
0x80 and then back to 0x01

I thought alot how to do so but failed to find any suitable idea. Is there any suggestion?

Many thanks for your kind considerations.
 
Last edited:

Hi assadmahmood,


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
unsigned short i;
for(i = 0x01; i != 0; i = (i << 1))
{
        // For 0x01, 0x02, ..., 0x80
}
 
for(i = 0x80; i != 0; i = (i >> 1))
{
        // For 0x080, 0x40, ..., 0x01
}





Regards,
Raj Gunaseelan
 
Last edited by a moderator:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top