'bitset'에 해당되는 글 2건

  1. 2015.02.07 bitset 을 이용한 퀘스트 완료목록 관리
  2. 2015.02.07 bitset
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

#include <bitset>
#include <limits>
using namespace std;


const int QUEST_SECTION = numeric_limits<char>::digits;
const int QUEST_SECTION_MAX = numeric_limits<char>::max();
const int QUEST_COUNT_COLUMN = 3;
const int QUEST_COUNT_MAX = QUEST_SECTION * QUEST_COUNT_COLUMN;


//---------------------------------------------------------------------------
// 설  명 : std::bitset 을 이용한 퀘스트 완료목록 테스트
// 인  자 : 
// 리턴값 : 
// 작성자 : 최민혁 - 작성일 : 2010-02-11 18:10:34
//---------------------------------------------------------------------------
int main()
{
    char data[QUEST_COUNT_COLUMN] = { 2, 4, 8 };
    char result[QUEST_COUNT_COLUMN] = { 0 };

std::bitset<QUEST_COUNT_MAX> completeList;
for( char i = 0; i < QUEST_COUNT_COLUMN; ++i )
{
    completeList |= (data[i] << (QUEST_SECTION * i));
}

std::bitset<QUEST_COUNT_MAX> marker(QUEST_SECTION_MAX);

for( char i = 0; i < QUEST_COUNT_COLUMN; ++i )
{
    result[i] = (char)((completeList >> (QUEST_SECTION * i)) & marker).to_ulong();
}


/*int alskdjf = completeList.to_ulong();

std::bitset<QUEST_COUNT_MAX> xxx;
std::bitset<QUEST_COUNT_MAX> aaa(2);
std::bitset<QUEST_COUNT_MAX> bbb(4);
std::bitset<QUEST_COUNT_MAX> ccc(8);

cout << xxx << endl;

int i = 0;
xxx |= (aaa << (QUEST_SECTION * i) );
++i;
xxx |= (bbb << (QUEST_SECTION * i) );
++i;
xxx |= (ccc << (QUEST_SECTION * i) );

cout << xxx << endl << endl;

i = 0;
cout << aaa << endl;
aaa <<= (QUEST_SECTION * i);
cout << aaa << endl;

++i;
cout << bbb << endl;
bbb <<= (QUEST_SECTION * i);
cout << bbb << endl;

++i;
cout << ccc << endl;
ccc <<= (QUEST_SECTION * i);
cout << ccc << endl;

std::bitset<QUEST_COUNT_MAX> fff(QUEST_SECTION_MAX);

i = 0;
std::bitset<QUEST_COUNT_MAX> temp(xxx);
temp.flip();
temp <<= (QUEST_SECTION * (QUEST_COUNT_COLUMN - 1 - i));
temp >>= (QUEST_SECTION * (QUEST_COUNT_COLUMN - 1 - i));
fff <<= (QUEST_SECTION * i);
int x = (temp ^= fff).to_ulong();

// 00000000000000000000000000000000
temp = xxx;
temp >>= (QUEST_SECTION * 1);
int y = (temp &= fff).to_ulong();
// 00000000000000000000000000000000

++i;
temp = xxx;
temp.flip();
temp <<= (QUEST_SECTION * (QUEST_COUNT_COLUMN - 1 - i));
temp >>= (QUEST_SECTION * (QUEST_COUNT_COLUMN - 1 - i));
fff <<= (QUEST_SECTION * i);
y = (temp ^= fff).to_ulong();

++i;
temp = xxx;
temp.flip();
temp <<= (QUEST_SECTION * (QUEST_COUNT_COLUMN - 1 - i));
temp >>= (QUEST_SECTION * (QUEST_COUNT_COLUMN - 1 - i));
fff <<= (QUEST_SECTION * i);
int z = (temp ^= fff).to_ulong();*/

return EXIT_SUCCESS;

}

'Programming > C / C++' 카테고리의 다른 글

공간 속의 두 점 사이의 거리  (0) 2015.02.07
stringstream  (0) 2015.02.07
EXIT_SUCCESS / EXIT_FAILURE  (0) 2015.02.07
numeric_limits  (0) 2015.02.07
bitset  (0) 2015.02.07
Posted by 역시인생한방
,

bitset

Programming/C / C++ 2015. 2. 7. 19:29
336x280(권장), 300x250(권장), 250x250, 200x200 크기의 광고 코드만 넣을 수 있습니다.

Proxy Pattern 으로 구현된 vector<bool>은 이런저런 문제가 있다는 것만 기억해 두시기 바랍니다

그러니 vector<bool>을 사용할 것이라면 bitset을 사용하세요


출처 : http://cafe.naver.com/cafec.cafe?iframe_url=/ArticleRead.nhn%3Fclubid=10026632%26page=1%26menuid=101%26boardtype=L%26articleid=56315

'Programming > C / C++' 카테고리의 다른 글

EXIT_SUCCESS / EXIT_FAILURE  (0) 2015.02.07
numeric_limits  (0) 2015.02.07
const 를 이용한 포인터 상수화  (0) 2015.02.07
override, abstract, __interface, sealed  (0) 2015.02.07
switch 분할 호출  (0) 2015.02.07
Posted by 역시인생한방
,