Results 1 to 4 of 4

Thread: Represent a bit vector

  1. #1
    Join Date
    Sep 2009
    Posts
    31
    Thanks
    7
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Represent a bit vector

    Hello people,

    I'm looking to manipulate a vector of bits, but some basic types like QBitArray, QByteArray not allow me to conversion string and be shown on the label.
    I also tried to use QVector.

    What do you recommend?

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Represent a bit vector


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

    Default Re: Represent a bit vector

    Qt Code:
    1. QBitArray ba(10);
    2. ba.setBit(5, true);
    3. ba.setBit(7, true);
    4.  
    5. QString text;
    6. for (int i = 0; i < ba.size(); ++i)
    7. text += ba.testBit(i) ? "1": "0";
    8. qDebug() << text;
    To copy to clipboard, switch view to plain text mode 
    You might like to reverse bit order.

    If you are manipulating a small number of bits then direct use of an unsigned int is also a possibility.
    Qt Code:
    1. unsigned int bitmap = 0;
    2. bitmap |= 1 << 5;
    3. bitmap |= 1 << 7;
    4. qDebug() << QString::number(bitmap, 2);
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Sep 2009
    Posts
    31
    Thanks
    7
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Represent a bit vector

    Thanks guys.

Similar Threads

  1. represent svg in tab view
    By Dilshad in forum Newbie
    Replies: 5
    Last Post: 27th July 2010, 09:47
  2. how to represent a graph?
    By harakiri in forum Qt Programming
    Replies: 2
    Last Post: 4th August 2009, 14:37
  3. vector of vector and computes
    By mickey in forum General Programming
    Replies: 1
    Last Post: 15th May 2008, 12:47
  4. insert in a vector of vector
    By mickey in forum General Programming
    Replies: 3
    Last Post: 6th March 2007, 08:45
  5. vector of vector size
    By mickey in forum General Programming
    Replies: 5
    Last Post: 13th February 2007, 15:59

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.