#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
using namespace std;
// Declare enum class with uint8_t underlying type for memory efficiency
enum class AdcConfig : uint8_t {
ChannelEnable = 1, // Binary: 0000 0001
InterruptEnable = 2, // Binary: 0000 0010
DMAEnable = 4 // Binary: 0000 0100
};
// Function to examine the bitmask and print enabled features
void printConfig(uint8_t cfg) {
bool anyEnabled = false;
// Check ChannelEnable (Bit 0)
if (cfg & static_cast<uint8_t>(AdcConfig::ChannelEnable)) {
cout << "ChannelEnable";
anyEnabled = true;
}
// Check InterruptEnable (Bit 1)
if (cfg & static_cast<uint8_t>(AdcConfig::InterruptEnable)) {
if (anyEnabled) cout << " "; // Add space if a previous flag was printed
cout << "InterruptEnable";
anyEnabled = true;
}
// Check DMAEnable (Bit 2)
if (cfg & static_cast<uint8_t>(AdcConfig::DMAEnable)) {
if (anyEnabled) cout << " ";
cout << "DMAEnable";
anyEnabled = true;
}
// If no bits were set, print "None"
if (!anyEnabled) {
cout << "None";
}
cout << endl;
}
int main() {
int ch, intr, dma;
if (!(cin >> ch >> intr >> dma)) return 0;
uint8_t cfg = 0;
// Combine inputs into the configuration byte using bitwise OR
if (ch) cfg |= static_cast<uint8_t>(AdcConfig::ChannelEnable);
if (intr) cfg |= static_cast<uint8_t>(AdcConfig::InterruptEnable);
if (dma) cfg |= static_cast<uint8_t>(AdcConfig::DMAEnable);
printConfig(cfg);
return 0;
}
Input
1 0 1
Expected Output
ChannelEnable DMAEnable