| | |
interfacing systems of different makes
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Feb 2009
Posts: 2
Reputation:
Solved Threads: 0
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????
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?
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
>>my problem is to convert the 32 bit float data to integer format
Simple -- just assign float to int
Now just send system2 the value of x.
Simple -- just assign float to int
C Syntax (Toggle Plain Text)
double n = 123.456; int x = (int)n; if( modf(n,0) > 0.5 x++;
Now just send system2 the value of x.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
What about this:
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.
C Syntax (Toggle Plain Text)
double n = 123.456; int x = (int)(n + .5);
![]() |
Similar Threads
Other Threads in the C Forum
- Previous Thread: All permutations of a string
- Next Thread: convert seconds to minutes, hours, days, months, years, etc.
| Thread Tools | Search this Thread |
#include * ansi append array arrays asterisks bash binarysearch centimeter changingto char character convert copyimagefile cprogramme creafecopyofanytypeoffileinc createprocess() database dynamic execv fgets file floatingpointvalidation fork framework function getlogicaldrivestrin givemetehcodez grade gtkwinlinux hacking histogram ide inches include infiniteloop initialization input interest intmain() iso kernel keyboard kilometer km license linked linkedlist linux list lists looping lowest matrix meter microsoft number oddnumber open opendocumentformat openwebfoundation overwrite owf pdf pointer pointers posix power probleminc process program programming radix recursion recv recvblocked research reversing segmentationfault sequential single socket socketprogramming standard strchr string suggestions systemcall test testing threads turboc unix urboc user variable wab whythiscodecausesegmentationfault windowsapi






