5
通过位运算转换大小写
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.
通过位运算转换大小写
位运算是计算机科学领域用的非常广泛的一种计算方式。再合理的使用方式下,会大大提升运算效率,今天就介绍一下位运算的一个巧妙应用:转换大小写字母。
针对这个问题,我们可以首先观察一下大小写字母的ascii码特点。
可以看到每一对大小写字母的ascii码值都是差32,对应到二进制上,就是只有第六位相反,其他的值都一样。
因此,用一个字母的值与 0010 0000 (32)作亦或,就可以得到它对应的大写或小写字母了。
欢迎关注我的其它发布渠道
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK