Solved

Hexa to float, how to?

Posted on 1997-05-02
2
296 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
Comment Utility
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
Comment Utility
Thanks very much for your support mr.emmons!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
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 switch statements in the C programming language.

771 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

11 Experts available now in Live!

Get 1:1 Help Now