Problem: Given an integer led as input, create a bitset (16 bits) with led bits set to 1. Then, create the following sequence (assume in this case led = 7):
0000000001111111 0000000000111111 0000000001011111 0000000001101111 0000000001110111 0000000001111011 0000000001111101 0000000001111110
Note that it is a "zero" that is moving to the right. The code I wrote is:
void create_mask(int led){
string bitString;
for (int i = 0; i < led; i++){
bitString += "1";
}
bitset<16> bitMap(bitString);
for (int i = led; i >= 0; i--){
bitMap[i] = false;
cout << bitMap << endl;
bitString = "";
for (int j = 0; j < led; j++){
bitString += "1";
}
bitMap = bitset<16> (bitString);
}
}
I don't like the nested loop where I set each bit to 0. I think that could be made better with less complexity.