|
-
March 25th, 2018, 08:23 AM
#1
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.
-
March 25th, 2018, 11:12 AM
#2
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.
-
March 25th, 2018, 12:46 PM
#3
Re: binary digit matrix implementation by using 2D vector
 Originally Posted by Kmilano
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.
-
March 25th, 2018, 12:56 PM
#4
Re: binary digit matrix implementation by using 2D vector
 Originally Posted by AvDav
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
-
March 26th, 2018, 12:31 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|