float to hex
-
A "hex" number is how it is represented, not how it is stored (i.e., its type). All numbers have a base-16 representation, be they floating-point or integer. For example, if I had a number (12345) and I wanted to see its base-16 representation, I'd use:
int num = 12345;
char szNum[16];
sprintf(szNum, "%#x", num);szNum
now contains "0x3039." No conversion was done, it's just shown in a different base. See if these two MSDN articles help you along any: Q42980 Q125056 -
A "hex" number is how it is represented, not how it is stored (i.e., its type). All numbers have a base-16 representation, be they floating-point or integer. For example, if I had a number (12345) and I wanted to see its base-16 representation, I'd use:
int num = 12345;
char szNum[16];
sprintf(szNum, "%#x", num);szNum
now contains "0x3039." No conversion was done, it's just shown in a different base. See if these two MSDN articles help you along any: Q42980 Q125056Thanks for the help. Where can I find those articles, on the msdn.microsoft site? Just to clarify: I am sending information from my program to someone else via the internet. I was told that the information has to be sent in hex format. So are you saying i can just send a float number? Thanks for all your help
-
Thanks for the help. Where can I find those articles, on the msdn.microsoft site? Just to clarify: I am sending information from my program to someone else via the internet. I was told that the information has to be sent in hex format. So are you saying i can just send a float number? Thanks for all your help
Jay Hova wrote: Where can I find those articles, on the msdn.microsoft site? Yes. Jay Hova wrote: Just to clarify: I am sending information from my program to someone else via the internet. I was told that the information has to be sent in hex format. So are you saying i can just send a float number? See this thread.
-
Thanks for the help. Where can I find those articles, on the msdn.microsoft site? Just to clarify: I am sending information from my program to someone else via the internet. I was told that the information has to be sent in hex format. So are you saying i can just send a float number? Thanks for all your help
I'm not sure what they're trying to say - "Hex format"? It could many several things. The IEEE format for representing a floating point number is S EEEEEEEE FFFFFFFFFFFFFFFFFFFFFFF 0 1 8 9 31 where S = the sign bit, EEEEEEEE = the exponent, and FFF...F = the fractional mantissa. In this format each bit has meaning, and on the receiving end the consumer has to expect and recognize this format. When you send it in hex, you're just sending bits in groups of 4, or SEEE EEEE EFFF FFFF FFFF FFFF FFFF FFFF Hex0 Hex1 Hex2 Hex3 Hex4 Hex5 Hex6 Hex7 It's up to the receiver to combine the 8 hex characters' bit pattern into a single 32-bit value and correctly interpret it as a floating point value. On the other hand, if your application requires you to send text data only, using the ascii characters that represent the hex characters that are equivalent to your floating point value, you have a real challenge. First you'll have to convert the float into a collection of 4-bit chunks, then determine the hex character for each chunk, then convert each hex character to text. I wouldn't know how to begin that, I'm afraid, though almost everyone here is smarter than I about such things and may be able to guide you. Hopefully you're dealing with the first case...
"Welcome to Arizona!
Drive Nice - We're Armed..."
- Proposed Sign at CA/AZ Border -
Jay Hova wrote: Where can I find those articles, on the msdn.microsoft site? Yes. Jay Hova wrote: Just to clarify: I am sending information from my program to someone else via the internet. I was told that the information has to be sent in hex format. So are you saying i can just send a float number? See this thread.
Great... While I'm off, straining my tiny brain to come up with something that might just pass for helpful, you pop in with an easy solution. Sheesh!:laugh:
"Welcome to Arizona!
Drive Nice - We're Armed..."
- Proposed Sign at CA/AZ Border -
Great... While I'm off, straining my tiny brain to come up with something that might just pass for helpful, you pop in with an easy solution. Sheesh!:laugh:
"Welcome to Arizona!
Drive Nice - We're Armed..."
- Proposed Sign at CA/AZ Border