5

通过位运算转换大小写

 2 years ago
source link: https://lichuanyang.top/posts/9193/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

通过位运算转换大小写

发表于

2018-11-14 更新于 2021-09-23

阅读次数: 510 Valine: 0

位运算是计算机科学领域用的非常广泛的一种计算方式。再合理的使用方式下,会大大提升运算效率,今天就介绍一下位运算的一个巧妙应用:转换大小写字母。

针对这个问题,我们可以首先观察一下大小写字母的ascii码特点。

letter_ascii.png

可以看到每一对大小写字母的ascii码值都是差32,对应到二进制上,就是只有第六位相反,其他的值都一样。

因此,用一个字母的值与 0010 0000 (32)作亦或,就可以得到它对应的大写或小写字母了。

原文地址:https://lcy362.github.io/posts/9193/

欢迎关注我的其它发布渠道


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK