How would you do it?
Posted: Sat Jun 02, 2007 9:07 pm
(C++ preferably)
This is pretty complicated for me to explain; maybe ill fail, but ill give it a try.
i have a number of bitsets, all the same size.
I want to OR them all and store the result in another bitset, still the same size.
I know for a fact that that OR and XOR will give the same result. AND will yield zero.
e.g. no two bitsets will have an active bit at the same position.
Anyway, it is easy to just make a function to do the task, but i keep thinking that there must be some clever trick.
First i thought about something like an union of pointers, then i thought again banged my head against the floor.
Somehow i got the idea that if i could get a variable to point to more than one place in memory it would give me the result i needed.
Be aware, sometimes weird thoughts happens.
some code:
I know this is some crappy code (or atleast i think it is), but it should explain it.
The thing is that "b_or_all" will have to be up to date at all times, and b1, b2, ... will be altered constantly, and so i will have to call "OR_THEM" constantly. that bothers me, so i ask you (the experts) how it can be done different, and it wouldnt hurt if i didnt need to worry about calling some function all the time.
This isnt one of my better posts and it deffinently reveals a huge gap in my programmig skills, but i hope you can help anyway.
This is pretty complicated for me to explain; maybe ill fail, but ill give it a try.
i have a number of bitsets, all the same size.
I want to OR them all and store the result in another bitset, still the same size.
I know for a fact that that OR and XOR will give the same result. AND will yield zero.
e.g. no two bitsets will have an active bit at the same position.
Anyway, it is easy to just make a function to do the task, but i keep thinking that there must be some clever trick.
First i thought about something like an union of pointers, then i thought again banged my head against the floor.
Somehow i got the idea that if i could get a variable to point to more than one place in memory it would give me the result i needed.
Be aware, sometimes weird thoughts happens.
some code:
Code: Select all
std::bitset<64> b1, b2, b3,b4;
std::bitset<64> b_or_all
void OR_THEM() {
b_or_all = b1 | b2 | b3 | b4;
}
The thing is that "b_or_all" will have to be up to date at all times, and b1, b2, ... will be altered constantly, and so i will have to call "OR_THEM" constantly. that bothers me, so i ask you (the experts) how it can be done different, and it wouldnt hurt if i didnt need to worry about calling some function all the time.
This isnt one of my better posts and it deffinently reveals a huge gap in my programmig skills, but i hope you can help anyway.