Friday, 15 August 2014

qt - Quickly convert raw data to hex string in c++ -


I am reading data from a file and trying to display raw data as 2 digit hex string .

I am using the QT framework, especially QEASTEdit.

I have applied a bunch of different methods and have almost completed what I want to do, though there are some unexpected errors in it.

1) Read in the data:

  ifstream file (file path, ios :: in | ios :: binary | ios :: eaten); If (file.is_open ()) {size = file.tellg (); Memblock = new four [size + 1]; File.seekg (0, IOS :: bck); File.read (memblock, size); File.close (); }   

2) Create a single castormon that will be used (because QFextAdit requires a Caststring):

  Qestring;   

3) Loop through the array by adding each sorted character of the Qestring S.

  int count = 0; For (i = 0; i   

Now it works fine, except that it reaches a character FF , it seems that FFFFFFFFFFFFFFFF

So my main questions are:

  1. Why only 'FF' characters appear as'FFFFFFFFFFFF '?
  2. There is a way to convert four data to 16 data-based without using the STString :: number

    I want this implementation to be as fast as possible, so if Springff can work, please tell me, because I think that the questioning may be: The number is sharp.

    QString can not be used for binary data instead QByteArray should be used. It can be easily made with a char * buffer and it can be easily converted to hex string using toHex .

      QByteArray array (memblock, size); TextEdit-> SetText (QString (array.toHex ()));    

No comments:

Post a Comment