Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Hexa to float, how to?

Posted on 1997-05-02
2
Medium Priority
?
313 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 4

Accepted Solution

by:
emmons earned 20 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
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…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files 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.
Suggested Courses

604 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