Last active
November 8, 2020 11:57
-
-
Save ronald112/a466ff4cc91b8bce14421ae80ad7d65e to your computer and use it in GitHub Desktop.
CharByteFlag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#define SET_BIT(value, bit_num) \ | |
((1 << bit_num) | value) | |
#define CLEAR_BIT(value, bit_num) \ | |
(~(1 << bit_num) & value) | |
#define CHECK_BIT(value, bit_num) \ | |
(value & (1 << bit_num)) ? true : false | |
class ByteFlag { | |
public: | |
ByteFlag() | |
{ | |
m_flag = CLEAR_BIT(m_flag, 0); | |
m_flag = CLEAR_BIT(m_flag, 1); | |
m_flag = CLEAR_BIT(m_flag, 2); | |
m_flag = CLEAR_BIT(m_flag, 3); | |
m_flag = CLEAR_BIT(m_flag, 4); | |
m_flag = CLEAR_BIT(m_flag, 5); | |
m_flag = CLEAR_BIT(m_flag, 6); | |
m_flag = CLEAR_BIT(m_flag, 7); | |
}; | |
bool checkFlag(const short& num) | |
{ | |
if (num < 8 && num >= 0) | |
return CHECK_BIT(m_flag, num); | |
else | |
throw "Not valid argument!"; | |
}; | |
void setFlag(const short& num) | |
{ | |
m_flag = SET_BIT(m_flag, num); | |
}; | |
void clearFlag(const short& num) | |
{ | |
if (num < 0 || num >= 8) | |
throw "Not valid argument!"; | |
m_flag = CLEAR_BIT(m_flag, num); | |
}; | |
private: | |
char m_flag = 0; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment