array of bytes to float conversion

Please check the frequently asked questions before posting to the forum.
Post Reply
Author
Message
bossa71
Posts: 11
Joined: 11 Feb 2015 10:15

array of bytes to float conversion

#1 Post by bossa71 » 24 Feb 2015 02:05

Hi,
I need to convert an array of bytes coming from the UART interface into a floating number in order to perform mathematical operations.
For example I receive the bytes 30382E34 which means the characters 08.4 and I need to convert into the floating number 8.4

Could you please give me a suggestion?

I'm using PIC16F family and mikroC 6.5.0.

thank you

bossa71
Posts: 11
Joined: 11 Feb 2015 10:15

Re: array of bytes to float conversion

#2 Post by bossa71 » 24 Feb 2015 11:55

Hi,
I've found a solution to convert a string like this "x1x2.x3" in a floating number:

float x_float;
char x[4];

x_float = (10*(x[0]-48))+(x[1]-48)+(0.1*(x[3]-48));


thank you anyway
Regard!!

Post Reply

Return to “mikroPascal FAQ”