convert char to hex, please help.. [Solved]
hi everyone,
i got a string from anther computer through serial port. i need to decode the character into hex value.
for example:
i get string "ABC", i need to calculate 0x41 + 0x42 + 0x43
how can i get the value of "A" in hex or in dec?
thanks in advance
Re: convert char to hex, please help..
Code:
int len=s.length();
int sum=0;
for(int i=0;i<len;i++)
{
ch= s.at(i);
sum+=ch.unicode();
}
Re: convert char to hex, please help..
Quote:
Originally Posted by
MrDeath
Code:
int len=s.length();
int sum=0;
for(int i=0;i<len;i++)
{
ch= s.at(i);
sum+=ch.unicode();
}
thanks Mr Death, it works.
i did not realize that the unicode is a number in decimal format, i need to go back to school :(
Re: convert char to hex, please help..
even i need to go back to school :)
Re: convert char to hex, please help..
A better (or should I say a perfect) example is available at Nokia Developer Community Wiki.
It goes like this:
Code:
/* hexadecimal 0xED8788DC is equivavelent to decimal 3985082588 */
bool ok;
uint appId = str.toUInt(&ok,16); //appId contains 3985082588
/* decimal 3985082588 is equivalent to hex ED8788DC */
uint decimal = 3985082588;
haxadecimal.setNum(decimal,16); //now hexadecimal contains ED8788DC
I hope this will help.