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?

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 .

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

Simple -- just assign float to int

double n = 123.456;
int x = (int)n;
if( modf(n,0) > 0.5
   x++;

Now just send system2 the value of x.

What about this:

double n = 123.456;
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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.