Results 1 to 3 of 3

Thread: QByteArray processing (seeking equivalent QT code)

  1. #1
    Join Date
    Jan 2008
    Posts
    107
    Thanks
    36
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Red face QByteArray processing (seeking equivalent QT code)

    Hi,

    Could someone please tell me the C++/Qt4 equivalent of this?

    PHP CODE

    Qt Code:
    1. $input_250="432345566180632659";
    2.  
    3. $input_Value=array();
    4.  
    5. //250 IN29
    6. $dec = $input_250;
    7. $byte = 8;
    8. for($i=0;$i<$byte;$i++)
    9. {
    10. if($i>0)
    11. {
    12. $input_Value[$i] = gmp_mod(gmp_div_q($dec,gmp_pow(2, $i*8)),256);
    13. }
    14. else
    15. {
    16. $input_Value[$i] = gmp_mod($dec,256);
    17. }
    18. }
    To copy to clipboard, switch view to plain text mode 

    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
    Last edited by pdoria; 12th July 2009 at 14:24. Reason: updated contents

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,677
    Thanks
    13
    Thanked 1,596 Times in 1,524 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default 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.
    Qt Code:
    1. // close to the original
    2. quint64 input250 = Q_UINT64_C(2314885536612049221);
    3. QByteArray inputValue(sizeof(input250), 0); // bytes of zero
    4. int i = 0;
    5. quint64 work = input250;
    6. while (work) { // only does as many loops as needed.
    7. inputValue[i++] = work & 0xff;
    8. work = work >> 8;
    9. }
    10. qDebug() << input250 << inputValue;
    11.  
    12. // You might get away with this but beware byte order issues
    13. QByteArray ba = QByteArray::fromRawData((char *)&input250, sizeof(input250));
    14. qDebug() << input250 << ba;
    To copy to clipboard, switch view to plain text mode 
    Last edited by ChrisW67; 13th July 2009 at 02:44.

  3. The following user says thank you to ChrisW67 for this useful post:

    pdoria (13th July 2009)

  4. #3
    Join Date
    Jan 2008
    Posts
    107
    Thanks
    36
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Thumbs up [SOLVED] QByteArray processing (seeking equivalent QT code)

    Chris,

    Either approach works perfectly.

    Many, many thanks!

    BR,
    Pedro Doria Meunier

Similar Threads

  1. problem with linking
    By mickey in forum Qt Programming
    Replies: 49
    Last Post: 12th August 2006, 22:41

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.