# Thread: Does anybody know how to convert binary data to hex?

1. I converted binary data to decimal with help of TLex:

Code:
```_LIT(str,"11");
TLex Binary_string(str);
TUint number(0);
Binary_string.Val(number,EBinary); Here EBinary it is system of str```
Does anybody know how to convert binary data to hex?

2. Hi,
use
TBuf<20> buf;
buf.Format("%x", val);

3. Just for fun, I think the following would work also to convert a 32bit binary integer to a hex string.

TBuf<20> aBuf;

for (TInt nibbleCount = 0; count < 8; count++)
{
TUint nibbleValue = number & nibbleMask;

if (nibbleValue == 0)
aBuf.Append('0')
else if (nibbleValue == 1)
aBuf.Append('1')
else if (nibbleValue == 2)
aBuf.Append('2')
...
else if (nibbleVAlue == 14)
aBuf.Append('E')
else if (nibbleVAlue == 15)
aBuf.Append('F');

number = number >> 4; //(this destroys the number so maybe need to copy
}

4. I did it in the next way:

Code:
```_LIT(str,"111111"); // binary data )
TLex Binary_string(str);
TUint number(0);
Binary_string.Val(number ,EBinary); //it converts char string str to int(Decimal) (EBinary it means that char string in binary format)
TBuf<16> converter;
converter.Num(number,EHex);//it converts int number(Decimal) to char string (Hex)```

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.