What I am trying to do is to convert hex string from double and then repeats.
The following code conversion does double-to-hex string
char * double2HexString (double A) {char * buf = new char [17]; // double is 8-byte long, so we have 2 * 8 + termination \ 0 char * d2c; D2c = (Four *) & amp; a; Char * n = buf; Int i; For (i = 0; i <8; i ++) {sprintoff (n, "% 02x", * d2c ++); N + = 2; } * (N) = '\ 0'; }
This works, however, I'm not sure how to change the string back in double form. Please ask for advice :)
I am surprised to see that no standard has come up with the solution, which That the % a
format specification in the ISO C99 standard
#include & lt; Iostream & gt; #include & lt; String & gt; # Include & lt; Stdio.h & gt; Std :: string double2hexastr (double D) {four buffers [25] = {0}; :: snprintf (buffer, 25, "% a", d); // TODO errors check buffer buffer; } Double Hexster 2 Double (Constrode :: String End) {Double D = 0.0; :: sscanf (s.c_str (), "% lA", & amp; D); // Check TODO Errors D; } Int main () {std :: cout & lt; & Lt; "0.1 in Hexadecimal:" & lt; & Lt; Double 2 Hexster (0.1) & lt; & Lt; Std :: endl; Std :: cout & lt; & Lt; "0x1.99999999999 Reading the AP-4, it is"; Std :: cout & lt; & Lt; Hexstra 2 Double ("0X1.99999999999 9 AP-4") & lt; & Lt; Std :: endl; }
Comments
Post a Comment