Created the bitwise_encoder.cpp

This commit is contained in:
Mathias Wagner 2023-11-11 23:21:27 +01:00
parent da59818ba7
commit 1b9b14b042
Signed by: Mathias
GPG Key ID: B8DC354B0A1F5B44

35
bitwise_encoder.cpp Normal file
View File

@ -0,0 +1,35 @@
#include <iostream>
using namespace std;
int main() {
int inventory = 0;
string input;
do {
cout << "Drücke Enter, um das Programm zu beenden." << endl;
cout << "Gib ein Item ein, um es zu aktivieren oder zu deaktivieren (IDS 1-10): ";
getline(cin, input);
if (input.empty()) break;
int item = stoi(input);
if (item < 1 || item > 10) {
cout << "Ungültiges Item. Bitte versuche es erneut." << endl;
continue;
}
if ((inventory & (1 << (item - 1))) != 0) {
inventory &= ~(1 << (item - 1));
cout << "Item #" << item << " wurde deaktiviert." << endl;
} else {
inventory |= 1 << (item - 1);
cout << "Item #" << item << " wurde aktiviert." << endl;
}
} while (!input.empty());
cout << "Dein Inventar als Bitset: " << inventory << endl;
return 0;
}