free 8051 Microcontroller Projects AVR PIC Microcontroller Projects Tutorials Ebooks Libraries, interfacing tutorials, lcd tutorial, stepper motor, dc motor 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems

 
8051 microcontroller 8051 microcontroller
Forums

Moderators: Ajay, Junied , abbas1707, Arun Kumar V, pdi33, Shailesh NAYAK, ۞ TPS ۞, shyam, sashijoseph
Author Post
nismo
Fri Aug 15 2008, 06:12AM
 User Offline
Registered Member #9479
Joined: Thu Jul 31 2008, 09:03AM

Posts: 77
Thanked 1 time in 1 posts
What >> and << do in C programming ??

Back to top


۞ TPS ۞
Fri Aug 15 2008, 10:14AM

 User Offline
Registered Member #2712
Joined: Tue Jul 31 2007, 12:06AM

Posts: 466
Thanked 62 times in 52 posts
less then greater than

Online Component Shoppe
http://www.onlinetps.com/
Components at cheap rates in India
Back to top


nismo
Sat Aug 16 2008, 04:13AM
 User Offline
Registered Member #9479
Joined: Thu Jul 31 2008, 09:03AM

Posts: 77
Thanked 1 time in 1 posts
۞ TPS ۞ wrote ...

less then greater than



Are you sure that it is greater or less than?? According to my textbook. >> means shift right and << shift left. But i don know where to apply both of them and how are are used...
Back to top


pdi33
Sat Aug 16 2008, 06:37AM

 User Offline
Registered Member #1329
Joined: Mon Jun 04 2007, 09:28AM

Posts: 621
Thanked 135 times in 131 posts
yes nismo,
u are right. these are indeed left/right shift operators. The most general use of these operators in our embedded c programming is to set/clear an individual bit of a single byte.
the left shift operator << is used in this case.
suppose u want to set the 'n' th bit of a register say reg1. then u can write the following instruction:
reg1 |=(1<<n);
similarly if u want to reset/clear a bit of the register u can use the instruction:
reg1 &=~(1<<n);
this logic is extensively used in AVR programming as AVRs have only byte level operations unlike 8051 which supports bit level manipulations .
the AVR library also included a macro _BV(n) which is equivalent to (1<<n) for this very reason.



* inspired to develop,developing to inspire *
Back to top


shyam
Sat Aug 16 2008, 10:10PM

 User Offline

Registered Member #2984
Joined: Mon Aug 06 2007, 11:33AM

Posts: 719
Thanked 107 times in 103 posts
pdi33 is right

x>>1
means the value of x be shifted one times towards right
like in
0000 0010 >>1 will give 0000 0001
similarly,


x<<1
means the value of x be shifted one times towards left
like in
0000 0010 <<1 will give 0000 0100


in some micro controllers bit addressing is not provided (ex. lpc2138)
there the whole (8 bit /32 bit) register needs to be read or written to.
in such a case you will need these (<<,>>) operators also known as bitwise shift operators.

ex. writing 1 to 5 bit of resister A
A = 0x01 << 5 ;
that will make A= 0010 0000 = 0x20
similarly if you want to read the status of the 5th bit of A register
(A>>5)&&(0x01) = result;

if the fifth bit is one u get result as 1
if not the result will be a zero..

hope that will make there use clearer!


lProgress is not made by early risers or hard workers, but by LAZY people, trying to find easier ways to do the same........
Back to top


 

Jump:     Back to top

Syndicate this thread: rss 0.92 Syndicate this thread: rss 2.0 Syndicate this thread: RDF
Powered by e107 Forum System

8051 Microcontroller Projects 8051 AVR tutorials PIC microcontroller, 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems