# Thread: How to convert TPtrC8 to TInt?

1. ## How to convert TPtrC8 to TInt?

the number is TPtrC8 is 20 digits... Can anyone please tell me how to convert the number? this is the code:

{
TPtrC8 token;
TBuf8 <512> buf;

for(TInt i=0; i<4; i++)
{
token.Set(lex.NextToken());
if(i==3)
{
buf.Append(token);
buf.Delete(0,4);
}
}

token.Set(buf.Alloc()->Des());

TInt oldId;
TLex8 temp(token);
temp.SkipSpace();
temp.Val(oldId);

return oldId;
}

kindly help ...

2. ## Re: How to convert TPtrC8 to TInt?

try using following code

Code:
```TInt TDes2TIntL(TDesC &aDesC)
{
TInt rstInt;
if(lexRec.Val(rstInt)!=KErrNone)
User::Leave(0);
return rstInt;
}```

3. ## Re: How to convert TPtrC8 to TInt?

Some other value is getting returned... instead of the right one.

4. ## Re: How to convert TPtrC8 to TInt?

try above function, it works as a charm.

5. ## Re: How to convert TPtrC8 to TInt?

Some other value is getting returned... instead of the right one.
What have you parsed, and what have you got?

6. ## Re: How to convert TPtrC8 to TInt?

Hello,

I was parsing a VCard and getting the UID... the uid is 20 digits. I guess TInt cannot hold such huge number... am I right?

8. ## Re: How to convert TPtrC8 to TInt?

I am not sure if you should really parse the UID field of a vCard, just search for vcard uid with Google.
And a 20-digit decimal number does not fit into a 64-bit integer, even if it is unsigned: 20 / log 2 is 66.438... thus you would need a 67 bit number for that.

9. ## Re: How to convert TPtrC8 to TInt?

Originally Posted by skumar_rao
try using following code

Code:
```TInt TDes2TIntL(TDesC &aDesC)
{
TInt rstInt;
if(lexRec.Val(rstInt)!=KErrNone)
User::Leave(0);
return rstInt;
}```
You should never leave with error code 0, because that code means no errors, (http://www.symbian.com/developer/tec...rr.h.variables), and leaving means an error occurred. Leave with the return value of TLex::Val instead.

10. ## Re: How to convert TPtrC8 to TInt?

Thank you for the replies. I solved the issue. The 20 digit UID was not fitting in the TInt. Hence I used TInt64. Now the application works just fine...

wizard_hu_, I am not parsing the UID but the VCard for UID.
Thank you and others for your time, I appreciate.

11. ## Re: How to convert TPtrC8 to TInt?

Note that 18446744073709551615 is the largest number fitting into a 64-bit unsigned integer. So there are more 20-digit numbers which do not fit into 64 bits, than those which accidentally fit. You would still need 67bits for covering them all.

12. ## Re: How to convert TPtrC8 to TInt?

The range of TInt64 is: 2^64 = +/-18446744073709551615.
The UID that I was receiving was 15061974036633400012. So it has worked.. Then what data type should I use?

13. ## Re: How to convert TPtrC8 to TInt?

A simple descriptor, and not a number, as already suggested. You will never need to do mathematical operations with the UID, so you do not lose anything.