PDA

View Full Version : How can you display binary data in hex format?



Cruz
4th February 2009, 13:43
Hi.

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



char buff[n];
int bytesRead = port->read(buff, n);


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?

caduel
4th February 2009, 14:33
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.

jpn
4th February 2009, 14:40
See QByteArray::toHex().