PDA

View Full Version : storing data in hexadecimal format



aj2903
12th January 2010, 14:22
hii....
i want to store data into file in hexadecimal format.

How can it be done ?

Follwing is the code I tried :




QFile fileC("test_1.hex");
QTextStream outC(&fileC);


unsigned char cData = 47;
outC << cData;l



The code writes 47,but in Char Format.How can we conver it into hexadecimal

wysota
12th January 2010, 14:57
Don't use QTextStream. Use QFile::write() instead.

caduel
12th January 2010, 14:58
if you want to store a single character, see QString::arg(), there are overloads that let you specify the base (choose 16 for hex). If you have more data, QByteArray::toHex() might interest you as well.

HTH

SABROG
12th January 2010, 15:06
outC << showbase << hex << uppercasebase << uppercasedigits << cData;

aj2903
13th January 2010, 05:16
thanks for replying
but still not able to get it right.

can someone display code snippet for the same

aj2903
13th January 2010, 05:21
thanks for replying
but still not able to get it right.

can someone display code snippet for the same

tsp
13th January 2010, 05:29
How about using QDataStream instead of QTextStream? QDataStream provides a serialization of binary data. The examples of data/text stream are part of the documentation.