×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Regular Contributor
    Join Date
    Feb 2008
    Location
    Russia Saint-Petersburg
    Posts
    61

    Does anybody know how to convert binary data to hex?

    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. #2
    Regular Contributor
    Join Date
    Nov 2007
    Location
    Ukraine
    Posts
    56

    Re: Does anybody know how to convert binary data to hex?

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

  3. #3
    Nokia Developer Expert
    Join Date
    Jul 2003
    Location
    Vancouver, Canada
    Posts
    220

    Post Re: Does anybody know how to convert binary data to hex?

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

    TBuf<20> aBuf;
    TUint nibbleMask = 0b00000000000000000000000000001111

    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
    }
    Last edited by billbonney; 2008-03-04 at 17:11. Reason: Made a mistake ;)

  4. #4
    Regular Contributor
    Join Date
    Feb 2008
    Location
    Russia Saint-Petersburg
    Posts
    61

    Re: Does anybody know how to convert binary data to hex?

    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)

Similar Threads

  1. Convert String into Hex
    By cashgoh in forum Symbian
    Replies: 3
    Last Post: 2008-08-28, 08:30
  2. Replies: 1
    Last Post: 2004-12-23, 07:20
  3. cimd tool query for sending binary data
    By patilraghu in forum General Messaging
    Replies: 1
    Last Post: 2002-09-10, 07:09
  4. Internet Access Config via Smart Message
    By ajbrindley in forum Smart Messaging
    Replies: 1
    Last Post: 2002-08-14, 07:56

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×