Convert int to Hex with fixed bytes
Hi,
i need to convert an int to hex and after to string but i need to do it with a fixed number of bytes per example:
int a=12;
qDebug()<<QString::number(tam, 16);
=="C" (it is ok)
but i need that the string always have for chars like= "000C"
There is an easy solution for it?
Re: Convert int to Hex with fixed bytes
Yes, read the whole documentation for the function you are using, you can pass more than two parameters to it :)
Re: Convert int to Hex with fixed bytes
Quote:
Originally Posted by
wysota
Yes, read the whole documentation for the function you are using, you can pass more than two parameters to it :)
i tried this: qDebug()<<QString::number(tam, 16, 4); and result is:
"12.0000" :s
EDIT1
I'm seeing this: QString QString::arg ( ulong a, int fieldWidth = 0, int base = 10, const QChar & fillChar = QLatin1Char( ' ' ) ) const
EDIT2
qDebug()<<QString("%1").arg(tam,4,16,QLatin1Char(' 0'));
i don't know if this is best way but works :)
"000c"
Re: Convert int to Hex with fixed bytes
It's ok. You can also do:
Code:
if(c.
size()<
4) c
= QString(4-c.
size(),
'0')+c;