473,385 Members | 1,317 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Shiftable, ANDable bit vector

Hello group,

I need a bit vector of a fixed size (which may well be known at
compiletime). The requirement is that it should be able to perform the
&, ^, |, ~ and <</>operations. I.e. something like (pseudocode):

dreamvector<12x, y, z;

x[0] = true;
x[4] = true;
x[8] = true;
y[4] = true;

z = x & y;
z <<= 3;

Which should result in z being:

CBA9876543210
0000010000000

Is something like this already present in the STL or do I have to
implement it by myself?

Kind regards,
Johannes

--
"Meine Gegenklage gegen dich lautet dann auf bewusste Verlogenheit,
verlästerung von Gott, Bibel und mir und bewusster Blasphemie."
-- Prophet und Visionär Hans Joss aka HJP in de.sci.physik
<48**********************@news.sunrise.ch>
Oct 27 '08 #1
1 1405
Johannes Bauer wrote:
Hello group,

I need a bit vector of a fixed size (which may well be known at
compiletime). The requirement is that it should be able to perform the
&, ^, |, ~ and <</>operations. I.e. something like (pseudocode):

dreamvector<12x, y, z;

x[0] = true;
x[4] = true;
x[8] = true;
y[4] = true;

z = x & y;
z <<= 3;

Which should result in z being:

CBA9876543210
0000010000000

Is something like this already present in the STL or do I have to
implement it by myself?
Write

...
#include <bitset>
#define dreamvector std::bitset
...

in front of your code.
It should read now:

....
#include <iostream>
#include <bitset>

#define dreamvector std::bitset

int main()
{
dreamvector<12x, y, z;

x[0] = true;
x[4] = true;
x[8] = true;
y[4] = true;

z = x & y;
z <<= 3;

std::cout << z << std::endl;

return 0;
}
....
Regards

Mirco
Oct 27 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: {AGUT2}=IWIK= | last post by:
Hello all, It's my fisrt post here and I am feeling a little stupid here, so go easy.. :) (Oh, and I've spent _hours_ searching...) I am desperately trying to read in an ASCII...
9
by: luigi | last post by:
Hi, I am trying to speed up the perfomance of stl vector by allocating/deallocating blocks of memory manually. one version of the code crashes when I try to free the memory. The other version...
7
by: Forecast | last post by:
I run the following code in UNIX compiled by g++ 3.3.2 successfully. : // proj2.cc: returns a dynamic vector and prints out at main~~ : // : #include <iostream> : #include <vector> : : using...
8
by: Ross A. Finlayson | last post by:
I'm trying to write some C code, but I want to use C++'s std::vector. Indeed, if the code is compiled as C++, I want the container to actually be std::vector, in this case of a collection of value...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.