Solved

Hexa to float, how to?

Posted on 1997-05-02
2
302 Views
Last Modified: 2011-10-03
I need to convert some hexadecimal code to float or double, how can I achive this?
ex:
I have in the code   2A ED 00 F2
what is the equivalent in a float number?
or double?
Is there any functiuon in C that performs this action?
0
Comment
Question by:Antonio050297
2 Comments
 
LVL 4

Accepted Solution

by:
emmons earned 10 total points
ID: 1250230
Assuming that the input characters are all upper case HEX digits, this should do the job of getting each byte into an int.
Then you can merge them together by just multiplies of 256.

float f;
f = byte2int( "2A");
f = 256 * f + byte2int( "ED");
f = 256 * f + byte2int( "00");
f = 256 * f + byte2int( "F2");

There is a tacit assumption here that the number that you are passing in is not stored in an odd way. If it is stored in memory as a float, than this will not work. Also, the above code might be exactly opposite of what you want, depending on the byte ordering of your architecture. Try it on a number that you know to verify the ordering.
int byte2int( char in[3]) /* 2 bytes and a null */
 {
int i;
i = 16 * (( in[0] > '9') ? in[0] - 'A' : in[0] - '0');
i += (( in[1] > '9') ? in[1] - 'A' : in[1] - '0');
return( i);
}
0
 

Author Comment

by:Antonio050297
ID: 1250231
Thanks very much for your support mr.emmons!
0

Featured Post

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
stack 22 159
How to create project in Eclipse ? 1 193
Understanding the meaning of Portability in Embedded System Programming 8 127
Passing command line arguments in C 10 85
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now