Urgent Convert from CString to hexadecimal
-
i want to convert a Cstring let's say CString s="1E"; unsigned char k; i want to convert it to be this way printf("k=%x",k); i want the result to be : k=1E how is this possible please i'm running out of time
emma :)
-
i want to convert a Cstring let's say CString s="1E"; unsigned char k; i want to convert it to be this way printf("k=%x",k); i want the result to be : k=1E how is this possible please i'm running out of time
emma :)
Have a look at ::strtol(...)[^].
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknown -
-
i want to convert a Cstring let's say CString s="1E"; unsigned char k; i want to convert it to be this way printf("k=%x",k); i want the result to be : k=1E how is this possible please i'm running out of time
emma :)
Will
CString::Format
be helpful ? Regards, Paresh. -
i want to convert a Cstring let's say CString s="1E"; unsigned char k; i want to convert it to be this way printf("k=%x",k); i want the result to be : k=1E how is this possible please i'm running out of time
emma :)
you can do:
k = strtol(s, &pStop, 16);
where
pStop
is a char pointer (seestrtol
documentation). of course you'll getk=0x1E
. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
no i want to enter it as i send before it is given in the code and not to be get as input
emma :)
look, i use
**ss**canf()
(with 2 s), notscanf()
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
no i want to enter it as i send before it is given in the code and not to be get as input
emma :)
imanos wrote:
it is given in the code and not to be get as input
and indeed
sscanf
does what you are requiring. see here [^]. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
imanos wrote:
it is given in the code and not to be get as input
and indeed
sscanf
does what you are requiring. see here [^]. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
-
Have a look at ::strtol(...)[^].
"It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknown -
Will
CString::Format
be helpful ? Regards, Paresh. -
you can do:
k = strtol(s, &pStop, 16);
where
pStop
is a char pointer (seestrtol
documentation). of course you'll getk=0x1E
. :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.