unsined int nBitFlag = 0xB; // BIN : 1011
지정값 넣기
int nLshIn = 2; // INT SIZE : 0 ~ 9 ( EX: 1 << 2 = BIN : 100 )
unsined int nValue = nBitFlag | (1 << nLshIn); // BIN : (1011 | 0100) = 1111 (0xF)
상위값만 뽑아낼 떄
unsined int nValue = (nBitFlag >> 1); // BIN : 1011 -> 101 (5)
AND 비교
if( nBitFlag & (1 << 2) ) // BIN : (1011 & 0100) -> false
if( nBitFlag & (1 << 1) ) // BIN : (1011 & 0010) -> true
OR 비교
if( nBitFlag | (1 << 2) ) // BIN : (1011 | 0100) -> true
if( nBitFlag | (1 << 1) ) // BIN : (1011 | 0010) -> true
지정값만 뺴기
int nLshOut = 1 << 1; // BIN : 0010 (2)
unsined int nValue = nBitFlag & ~(1 << nLshOut); // BIN : (1011 & ~(0010)) = 1001 (9)
-----------------------------------
enum E_BIT_FLAG
{
eBIT_00_0000_0000 = 0x000,
eBIT_00_0000_0001 = 0x001,
eBIT_00_0000_0010 = 0x002,
eBIT_00_0000_0100 = 0x004,
eBIT_00_0000_1000 = 0x008,
eBIT_00_0001_0000 = 0x010,
eBIT_00_0010_0000 = 0x020,
eBIT_00_0100_0000 = 0x040,
eBIT_00_1000_0000 = 0x080,
eBIT_01_0000_0000 = 0x100,
eBIT_10_0000_0000 = 0x200, // 10 Length -> __int32 MAX SIZE
eBIT_0000_0000_0100_0000_0000 = 0x00400,
eBIT_0000_0000_1000_0000_0000 = 0x00800,
eBIT_0000_0001_0000_0000_0000 = 0x01000,
eBIT_0000_0010_0000_0000_0000 = 0x02000,
eBIT_0000_0100_0000_0000_0000 = 0x04000,
eBIT_0000_1000_0000_0000_0000 = 0x08000,
eBIT_0001_0000_0000_0000_0000 = 0x10000,
eBIT_0010_0000_0000_0000_0000 = 0x20000,
eBIT_0100_0000_0000_0000_0000 = 0x40000, // 19 Length -> signed __int64 MAX SIZE
eBIT_1000_0000_0000_0000_0000 = 0x80000, // 20 Length -> unsigned __int64 MAX SIZE
// UTIL
eBIT_BEGIN = eBIT_00_0000_0001,
eBIT_END = eBIT_1000_0000_0000_0000_0000,
};
// LSH = <
enum E_LSH_FLAG // LSH_Flag -> <<
{
eLSH_00_0000_0001 = 0, // 1 << 0 -> (2진수) 0000 0001
eLSH_00_0000_0010 = 1, // 1 << 1 -> (2진수) 0000 0010
eLSH_00_0000_0100 = 2, // 1 << 2 -> (2진수) 0000 0100
eLSH_00_0000_1000 = 3, // 1 << 3 -> (2진수) 0000 1000
eLSH_00_0001_0000 = 4, // 1 << 4 -> (2진수) 0001 0000
eLSH_00_0010_0000 = 5, // 1 << 5 -> (2진수) 0010 0000
eLSH_00_0100_0000 = 6, // 1 << 6 -> (2진수) 0100 0000
eLSH_00_1000_0000 = 7, // 1 << 7 -> (2진수) 1000 0000
eLSH_01_0000_0000 = 8, // 1 << 8
eLSH_10_0000_0000 = 9, // 1 << 9 // 10 Length -> __int32 MAX SIZE
eLSH_0000_0000_0100_0000_0000 = 10,
eLSH_0000_0000_1000_0000_0000 = 11,
eLSH_0000_0001_0000_0000_0000 = 12,
eLSH_0000_0010_0000_0000_0000 = 13,
eLSH_0000_0100_0000_0000_0000 = 14,
eLSH_0000_1000_0000_0000_0000 = 15,
eLSH_0001_0000_0000_0000_0000 = 16,
eLSH_0010_0000_0000_0000_0000 = 17,
eLSH_0100_0000_0000_0000_0000 = 18, // 19 Length -> signed __int64 MAX SIZE
eLSH_1000_0000_0000_0000_0000 = 19, // 20 Length -> unsigned __int64 MAX SIZE
// UTIL
eLSH_BEGIN = eLSH_00_0000_0001,
eLSH_END = eLSH_1000_0000_0000_0000_0000,
};
// EDIT
#define CALCULATION_LSH(x) (1 << (x))
#define CALCULATION_LSH_64(x) (1i64 << (x))
'[ Programing ] > Algorithm' 카테고리의 다른 글
매주 이벤트(퀘스트) 주차 초기화 계산. (0) | 2022.04.21 |
---|---|
[C++] mt19937 난수 생성기 (Random 클래스) (0) | 2019.11.21 |
Tip 클래스 객체 생성과 초기 선언을 한줄로... (0) | 2016.07.25 |
설정된 기간 관련 카운터(주간) 계산하기 (0) | 2014.01.10 |
SYSTEMTIME 시간 차이 TickTime -> Day 계산. mktime, difftime (0) | 2013.12.20 |