用位(与和或)操作实现字母大小写转换

版权声明:本文为博主原创文章,转载需标明出处。 https://blog.csdn.net/coderDogg/article/details/86373095
//小写转大写
#include <iostream>
using namespace std;
int main(){
	char a = 'c';
	char b = a&(0b11011111);
	cout<<b<<endl;
} 
//大写转小写
#include <iostream>
using namespace std;
int main(){
	char a = 'A';
	char b = a | (0b00100000);
	cout<<b<<endl;
} 

大写字母与小写字母的 ASCII 码之间的关系:

'a':61h,即01100001

'A':41h,即01000001

猜你喜欢

转载自blog.csdn.net/coderDogg/article/details/86373095