• 【C++】位操作的应用


    // test.cpp : 定义控制台应用程序的入口点。
    //
    
    #include "stdafx.h"
    #include <Windows.h>
    #include <iostream>
    using namespace std;
    
    #define MAX_ACHIEVE_DATA_SIZE 256   					//成就的最大的BYTE数量
    char m_achieveFinishState[MAX_ACHIEVE_DATA_SIZE];       //成就的完成状态和领取奖励的状态
    
    void SetAchieveFinished(INT_PTR nAchieveId)
    {
    	INT_PTR  nBytePos = nAchieveId >> 2;		//第多少个BYTE
    	INT_PTR  nBitPos = (nAchieveId &3) << 1;    //一个BYTE里的第几个Bit
    	m_achieveFinishState[nBytePos] |= (BYTE)(1 << nBitPos) ;
    }
    bool IsAchieveFinished(INT_PTR nAchieveId)
    {
    	INT_PTR  nBytePos = nAchieveId >> 2;		//第多少个BYTE
    	INT_PTR  nBitPos = (nAchieveId & 3) << 1 ;  //一个BYTE里的第几个Bit
    	if( m_achieveFinishState[nBytePos] & (BYTE)(1 << nBitPos) )
    	{
    		return true;
    	}
    	return false;
    }
    //是否已经领取过成就的奖励了
    inline bool IsAchieveGiveAwards(INT_PTR nAchieveId)
    {
    	INT_PTR  nBytePos = nAchieveId >> 2; //第多少个BYTE
    	INT_PTR  nBitPos = ((nAchieveId &3) << 1) +1;  //一个BYTE里的第几个Bit
    	if( m_achieveFinishState[nBytePos] & (BYTE)(1 << nBitPos) )
    	{
    		return true;
    	}
    	return false;
    }
    //设置已经领取过成就的奖励了
    inline bool SetAchieveGiveAwards(INT_PTR nAchieveId)
    {
    	INT_PTR  nBytePos = nAchieveId >> 2;			//第多少个BYTE
    	INT_PTR  nBitPos = ((nAchieveId &3) <<1) +1;	//一个BYTE里的第几个Bit
    	m_achieveFinishState[nBytePos] |=  (BYTE)( 1 << nBitPos );
    	return true;
    }
    int _tmain(int argc, _TCHAR* argv[])
    {
    	int nAchieveId = 1;
    	SetAchieveFinished( nAchieveId);
    	SetAchieveGiveAwards(nAchieveId);
    	cout<<IsAchieveFinished(nAchieveId)<<endl;
    	cout<<IsAchieveGiveAwards(nAchieveId)<<endl;
    	nAchieveId = 2;
    	cout<<IsAchieveFinished(nAchieveId)<<endl;
    	cout<<IsAchieveFinished(nAchieveId)<<endl;
    	system("pause");
    	return 0;
    }
    
    


     

  • 相关阅读:
    maya粒子生成曲线
    jcFeather 1.5 视频教程系列
    maya 粒子制作海洋岸边convected foam
    maya curveflow修改
    jcFeather 免费限制版本
    欢迎
    用Maya切菜
    easyui 个人使用心得之下拉列表
    SQlServer时间的操作
    数字形式的人民币转换为大写形式
  • 原文地址:https://www.cnblogs.com/byfei/p/6389674.html
Copyright © 2020-2023  润新知