?? bitoperate.cpp
字號:
// BitOperate.cpp: implementation of the BitOperate class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "BitOperate.h"
#include "iostream.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
BitOperate::BitOperate()
{
}
BitOperate::~BitOperate()
{
}
/*
功能:把ch從右數的第position位設置為value;
*/
byte BitOperate::bitSet(byte ch, short position, bool value)
{
byte temp = ch;
if(position>8||position<1)
{
cout<<"Out of Bound! Position must be a number between 1 --- 8 "<<endl;
return ch;
}
bool bit = bitAt(temp,position);
if(bit^value)//如果不相同的話
{
if(bit == 0)
{
byte m = (byte)value;
for(int i = 1;i<position;i++)
m = m<<1;
ch+=m;
return ch;
}
else
{
byte m = (byte)bit;
for(int i = 1;i<position;i++)
m = m<<1;
ch-=m;
return ch;
}
}
else return ch;
}
/*
功能:返回ch從右數第i位的值;
*/
bool BitOperate::bitAt(byte ch, short position)
{
byte temp = ch;
if(position>8||position<1)
{
cout<<"Out of Bound! Position must be a number between 1 --- 8 "<<endl;
return false;
}
for(int j = 1;j<position;j++)
temp = temp>>1;
if(temp%2==0)return 0;
else return 1;
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -