QByteArray processing (seeking equivalent QT code)
Hi,
Could someone please tell me the C++/Qt4 equivalent of this?
PHP CODE
Code:
$input_250="432345566180632659";
$input_Value=array();
//250 IN29
$dec = $input_250;
$byte = 8;
for($i=0;$i<$byte;$i++)
{
if($i>0)
{
$input_Value[$i] = gmp_mod(gmp_div_q($dec,gmp_pow(2, $i*8)),256);
}
else
{
$input_Value[$i] = gmp_mod($dec,256);
}
}
I'm storing the $input_250 in Qt in a QByteArray.
This number is represented as a longlong .
Any help would surely be appreciated! ;)
BR,
Pedro Doria Meunier
Re: QByteArray processing (seeking equivalent QT code)
If I'm reading that right then you are trying to break a 64-bit integer value into a series of bytes.
Code:
// close to the original
quint64 input250 = Q_UINT64_C(2314885536612049221);
QByteArray inputValue
(sizeof(input250
),
0);
// bytes of zero int i = 0;
quint64 work = input250;
while (work) { // only does as many loops as needed.
inputValue[i++] = work & 0xff;
work = work >> 8;
}
qDebug() << input250 << inputValue;
// You might get away with this but beware byte order issues
qDebug() << input250 << ba;
[SOLVED] QByteArray processing (seeking equivalent QT code)
Chris,
Either approach works perfectly. ;)
Many, many thanks!
BR,
Pedro Doria Meunier