CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2018
    Posts
    40

    binary digit matrix implementation by using 2D vector

    How I can implement the following matrix by using just 2D vector (not matrix,...) in C++?
    HTML Code:
    0 0 0 1 1 1 1
    0 1 1 0 0 1 1
    1 0 1 0 1 0 1
    Above matrix is just an example and its 3 digit binary numbers except column contain 0 0 0.

    I need a code which I can extend a number of rows to 4 digits, 5, 6,... for other classes(in each class the number of rows will change)and I need a piece of code which I can use in all classes, commonly.

  2. #2
    Join Date
    Jun 2003
    Location
    Armenia, Yerevan
    Posts
    720

    Re: binary digit matrix implementation by using 2D vector

    The Boost library has dynamic_bitset templated class, you can use it along with std::vector in order to achieve the necessary functionality.

  3. #3
    Join Date
    Feb 2017
    Posts
    674

    Re: binary digit matrix implementation by using 2D vector

    Quote Originally Posted by Kmilano View Post
    I need a code which I can extend a number of rows to 4 digits, 5, 6,... for other classes(in each class the number of rows will change)and I need a piece of code which I can use in all classes, commonly.
    If the number of binary digits has an upper limit, say 32, you can store the columns as unsigned ints. A bit sequence is an integral number really, like 000=0, 001=1, 010=2, 011=3 etcetera. To read/write the individual bits in an unsigned int you can use the so called bit-wise operations available in C++. The matrix then becomes a 1D vector of unsigned ints and could be the same for all classes.
    Last edited by wolle; March 25th, 2018 at 12:49 PM.

  4. #4
    Join Date
    Feb 2017
    Posts
    674

    Re: binary digit matrix implementation by using 2D vector

    Quote Originally Posted by AvDav View Post
    The Boost library has dynamic_bitset
    And there's the std::bitset in the C++ standard library.
    Last edited by VictorN; March 25th, 2018 at 01:28 PM. Reason: corrected QUOTE tag

  5. #5
    Join Date
    Feb 2017
    Posts
    674

    Re: binary digit matrix implementation by using 2D vector

    The same OP has posted here asking about a concrete implementation,

    http://forums.codeguru.com/showthrea...sing-2D-vector

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured