943,936 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 584
  • C RSS
Feb 23rd, 2009
0

interfacing systems of different makes

Expand Post »
I have a problem of interfacing 2 systems of different manufacturers.While one system sends data in 32-bit floating format,the other system understands data only in integer format(16 bit ,32 bit etc).my problem is to convert the 32 bit float data to integer format that can be recognized by 2nd system(its the second system where the data is displayed).I am planning to use a 51 series micro controller with RS232.Can you provide me with a code that will convert 32 bit float serial data to integer format????
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kshitijkapoor is offline Offline
2 posts
since Feb 2009
Feb 23rd, 2009
0

Re: interfacing systems of different makes

I think first you have to understand how the 2nd system is going to display the values: If system 1 has 5.123 what is system2 going to do with it? should system1 send 5123, or just 5, or what?
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005
Feb 26th, 2009
0

Re: interfacing systems of different makes

If system 1 has 5.123 then system 2 needs to display 5 In other words we need to do rounding off.if system 1 gives 5.987 then system 2 should display 6 .
Reputation Points: 10
Solved Threads: 0
Newbie Poster
kshitijkapoor is offline Offline
2 posts
since Feb 2009
Feb 26th, 2009
0

Re: interfacing systems of different makes

>>my problem is to convert the 32 bit float data to integer format

Simple -- just assign float to int
  1. double n = 123.456;
  2. int x = (int)n;
  3. if( modf(n,0) > 0.5
  4. x++;

Now just send system2 the value of x.
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,953 posts
since Aug 2005
Feb 26th, 2009
0

Re: interfacing systems of different makes

What about this:
  1. double n = 123.456;
  2. int x = (int)(n + .5);
If the decimal portion is .5 or greater, the addition will carry it up to the next higher integer. I would think it would be quite a bit faster.
Reputation Points: 128
Solved Threads: 43
Posting Whiz
death_oclock is offline Offline
389 posts
since Apr 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: All permutations of a string
Next Thread in C Forum Timeline: Mapping Sonar Data with C





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC