File: hexconvertor.cpp

package info (click to toggle)
qsstv 9.5.8-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 10,928 kB
  • sloc: cpp: 47,579; makefile: 4
file content (28 lines) | stat: -rw-r--r-- 494 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "hexconvertor.h"

bool hexFromString(QString s,QByteArray &ba,bool toHex)
{
  int i,j;
  unsigned char res;
  bool ok;
  QString tmp;
  if(toHex)
    {
      if((s.length()&1)!=0) return false;
      ba.resize(s.length()/2);
      for(i=0,j=0;i<s.length();i+=2,j++)
        {
          tmp="0x";
          tmp+=s.mid(i,2);
          res=tmp.toInt(&ok,16);
          if(!ok) return false;
          ba[j]=res;
        }
    }
  else
    {
      ba=s.toLatin1();
    }
  return true;
}