Results 1 to 3 of 3

Thread: How can you display binary data in hex format?

  1. #1
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    387
    Thanks
    101
    Thanked 15 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default How can you display binary data in hex format?

    Hi.

    After reading from a serial port I have a bunch of binary data in a char buffer.

    Qt Code:
    1. char buff[n];
    2. int bytesRead = port->read(buff, n);
    To copy to clipboard, switch view to plain text mode 

    I want to scrutinize the data byte by byte and display each byte in a hexadecimal format like this: 0x01 0x1F 0xFE ...

    Can you please point me in the right direction?

  2. #2
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How can you display binary data in hex format?

    you can use QString::arg() to format a number for any base (16 for hex).
    iterate over your bytes and print each that way and you have what you want.

  3. The following user says thank you to caduel for this useful post:

    Cruz (4th February 2009)

  4. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: How can you display binary data in hex format?

    J-P Nurmi

  5. The following user says thank you to jpn for this useful post:

    Cruz (4th February 2009)

Similar Threads

  1. Best way to display lots of data fast
    By New2QT in forum Newbie
    Replies: 4
    Last Post: 16th October 2008, 22:46
  2. How can I read binary data to QString?
    By zolookas in forum Newbie
    Replies: 2
    Last Post: 29th July 2008, 20:03
  3. Some very weird compilation warnings
    By MarkoSan in forum Qt Programming
    Replies: 21
    Last Post: 23rd January 2008, 16:48
  4. First attempt to display serial port data on GUI
    By ShaChris23 in forum Newbie
    Replies: 12
    Last Post: 4th May 2007, 09:14
  5. How to convert binary data to hexadecimal data
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 8th March 2006, 16:17

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.