Results 1 to 4 of 4

Thread: QBitArray (the smallest unit of them all)

  1. #1
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QBitArray (the smallest unit of them all)

    I have a buffer (char [variable]) and i want to inspect this bit by bit hence like a big bit array.

    Is it possible to use a QBitArray in this case? if so please give me snippet of how to make this buffer into a bit array.

    baray98

    p.s. "variable" is known before doing all these processing

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QBitArray (the smallest unit of them all)

    I wouldn't do that. The class seems to be a bit crude to operate on. For instance you'd have to copy your array bit by bit into the object thus iterating it manually first, so I think there is no sense to double the work.

  3. #3
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QBitArray (the smallest unit of them all)

    You can work directly on the char array:
    Qt Code:
    1. bool bit( char c, int b)
    2. {
    3. char mask = (1 << b);
    4. return (c&mask==mask)?true:false;
    5. }
    To copy to clipboard, switch view to plain text mode 
    where b is the bit you want to test( 0 to 7).
    Returns true if the bit is set, false otherwise.

  4. #4
    Join Date
    Aug 2007
    Posts
    275
    Thanks
    28
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QBitArray (the smallest unit of them all)

    my main goal is to read a char buffer (variable size) as K size units, where k can 1 bit to 32 bits. example if i am given a buffer pointer and a K of 2 then I will go through the buffer and read them 2 bits at time. please guide me on how to implement these in a very efficient manner.

    baray98

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.