Results 1 to 15 of 15

Thread: Bitwise shifting and ORing HexaDecimal Value

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #13
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Wiki edits
    17

    Default Re: Convert QByteArray to quint 16

    Your code will output nothing because it never puts anything in the result QByteArray (compare line 10 and 11). Even if it did your result would not be what you expect.

    A QByteArray stores bytes, nothing else. As in my last post you want to look at the QVector or QList templates to store other types.

    Qt Code:
    1. ByteArray ba; // an array of bytes (chars actually)
    2. ba[0] = 0x1d;
    3. ba[1] = 0x17;
    4. ba[2] = 0x11;
    5. ba[3] = 0x00;
    6.  
    7. QList<quint16> result; // A list of 16 bit unsigned integers
    8.  
    9. for (int i = 0; i < ba.size(); i+=2)
    10. result.append(
    11. (static_cast<unsigned char>(ba.at(i) << 5))
    12. | static_cast<unsigned char>(ba.at(i+1))
    13. );
    14. }
    To copy to clipboard, switch view to plain text mode 
    You have to convert result to hex entry by entry, there is no toHex() to rely on. If you don't need the result retained in binary form (i.e. the result QList) then you can build the hex string as you go along. Conversion

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

    nagabathula (19th November 2010)

Similar Threads

  1. Shifting a QImage up by 1 pixel row
    By MSUdom5 in forum Qt Programming
    Replies: 2
    Last Post: 7th May 2010, 10:25
  2. LineEdit for Hexadecimal input
    By mastupristi in forum Qt Programming
    Replies: 2
    Last Post: 21st January 2010, 14:51
  3. how to process hexadecimal
    By mohanakrishnan in forum Qt Programming
    Replies: 2
    Last Post: 20th November 2009, 04:33
  4. Byte shifting in C
    By tntcoda in forum General Programming
    Replies: 3
    Last Post: 14th November 2008, 22:40
  5. Replies: 2
    Last Post: 4th August 2008, 08:14

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
  •  
Qt is a trademark of The Qt Company.