I want to do the conversion for the following type mention above. I am stuck of doing it. Is anyone have any idea of doing the conversion above? Thank you very much.
I want to do the conversion for the following type mention above. I am stuck of doing it. Is anyone have any idea of doing the conversion above? Thank you very much.
You're mixing concepts. Int and float are c data types. hex is a display format. How a number is stored is quite separate from how a number is displayed. What do you actually want to be changing?
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.
int and float are two different data types not display formats.
You can cast a float to an int which will throw away the fractional part (e.g. 12.34 will become 12) but going back from the int to float won't add it again.
But as long as you don't change your float variable that's not a problem.
Can you give an example code of what you want to achieve?
Bye, Andreas
Assuming you mean a hex string, you still need to specify how you want to convert it.
It's like saying you want to convert a circle to a square. We don't know if you want to cut round pieces off it, or add on some flat edges, or squash it into shape, and clearly the results are not the same.
I can think of more than two ways to convert a float to a hex string.
You also wont get any code from us without showing what you have tried.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
I don't think anyone can help before we know what you want to see.
Suppose you had a program that worked. What kind of output is there?
I think I know what function you need.
modf - Math.h - C - C++ Computing Reference with Worked Examples
Now, you will need to do some additional math before you convert the fractional portion to hex, but I think you know how to make integers hex, so you should be able to figure it out.
C doesn't have a built in function to print floating point numbers in hex. You'll have to write one yourself. For the rest, you can use printf.
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.
Sure it does--the 'a' and 'A' conversion specifiers print floating point numbers in hexadecimal (at least in C99 and later). printf(3): formatted output conversion - Linux man page
Example:
Output:Code:#include <stdio.h> int main(void) { printf("%a\n", 3.1415927); return 0; }
Code:0x1.921fb5a7ed197p+1
It is too clear and so it is hard to see.
A dunce once searched for fire with a lighted lantern.
Had he known what fire was,
He could have cooked his rice much sooner.