Bitwise Problem [Solved - a typo]



  • I ran the following snippet:

    quint32 a1, a2, zz;

    a1 = 0x0000AB8F;
    a2 = 0x00FCE888;

    zz = a2 & a1; //Bitwise AND

    QString astr1 = QString("%1").arg(a1, 16, 16, QLatin1Char('0') );
    cout << "\n a1 "<<astr1.toUpper().toStdString() << " "<<a1;

    QString astr2 = QString("%1").arg(a2, 16, 16, QLatin1Char('0') );
    cout << "\n a2 "<<astr2.toUpper().toStdString() << " "<<a2;

    QString zzstr = QString("%1").arg(zz, 16, 16, QLatin1Char('0') );
    cout << "\n zz "<<zzstr.toUpper().toStdString() << " "<<zz;

    cout << "\n ";

    QString mystr1;
    mystr1.setNum(a1,2);
    QString urstr1 = QString("%1").arg(mystr1, 32, '0' );
    cout << "\n a1 "<< urstr1.toStdString();

    QString mystr2;
    mystr2.setNum(a2,2);
    QString urstr2 = QString("%1").arg(mystr2, 32, '0' );
    cout << "\n a2 "<< urstr2.toStdString();

    QString mystrz;
    mystrz.setNum(a1,2);
    QString urstrz = QString("%1").arg(mystrz, 32, '0' );
    cout << "\n zz "<< urstrz.toStdString();

    cout << "\n ";

    and got this as a result:

    a1 000000000000AB8F 43919
    a2 0000000000FCE888 16574600
    zz 000000000000A888 43144

    a1 00000000000000001010101110001111
    a2 00000000111111001110100010001000
    zz 00000000000000001010101110001111
    This appears to be incorrect. What am I doing wrong?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.