how to put hex numbers into a Qbytearray?

Hello,
Can anyone suggest me about how to use hex number which are in ASCII form as a Qbytearray?
Actually I am converting my decimal number into hex number which is then stored as its ascii character using this functionQByteArray double2HexString(double n) { unsigned char hexaDeciNum[20]; QByteArray hexbyte ; int i = 0; while(n!=0) { int temp = 0; temp = n % 16; if(temp < 10) { hexaDeciNum[i] = temp + 48; i++; } else { hexaDeciNum[i] = temp + 55; i++; } n = n/16; } for(int j=i1; j>=0; j) cout << hexaDeciNum[j]; hexbyte = QByteArray((char*)hexDeciNum,20); return hexbyte; }
which then I need to send to another function which is storing the hex number into an array using this function byte by byte.
void writeout_RS5(){ QByteArray writedata_RS5; QByteArray value; qDebug()<<"helloooooooooo"; writedata_RS5=double2HexString(data); value[0]= writedata_RS5[0]; value[1]= writedata_RS5[1]; qDebug()<<writedata_RS5.toHex();
Where m I wrong?
What can I do now?
Can anyone help?[Added code tags ~kshegunov]

@Nimika There is a much much easier way to convert numbers to hex: http://doc.qt.io/qt5/qstring.html#number

@jsulm said in how to put hex numbers into a Qbytearray?:
@Nimika There is a much much easier way to convert numbers to hex: http://doc.qt.io/qt5/qstring.html#number
Or even a QByteArray::number since you want to store the result in a QByteArray

@mostefa if we go that far, QByteArray accepts an int value as constructor:
QByteArray byteArray1(61455); //or QByteArray byteArray2(0xF00F);