CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Swapping two variables

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jasbone123



Joined: 07 Oct 2009
Posts: 1

View user's profile Send private message

Swapping two variables
PostPosted: Wed Oct 07, 2009 2:01 am     Reply with quote

Hi ,

I want to swap two variables without using temporary variable.
So anyone give me solution.
_________________
JACOB
Guest








PostPosted: Wed Oct 07, 2009 5:47 am     Reply with quote

Sounds like a homework question...

Really easy though, 3 ways come to mind

If variables are 8bit...

write variables to eeprom and then read back(works for 16,32 bits as well)

write variables to I/O port and then read back

use Bit_functions on the two variables(takes a 'bit' of thinking)

write to serial buffer and read back....

oops that's more than 3 ways....

have fun.

Jay
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Wed Oct 07, 2009 6:02 am     Reply with quote

This does sound like a homework question!

I do know the answer Smile

A = n1
B = n2

A = A.B
B = A.B
A = A.B

A == n2
B == n1

The . represents a standard logical function, can you guess what it is ?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group