标签:位操作 rar array i++ string 测试 info img har
ch | 0b00100000
即 ch | 0x20
即 ch | 32
效果:A-Z
-> a-z
,小写字母、数字、大部分标点符号不变。_
变成了奇怪的字符。
测试:
public static void main(String[] args) {
String s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz"
+ "1234567890"
+ "[]\\;‘,./"
+ "!@#$%^&*()_+{}|:\"<>?";
char[] chars = s.toCharArray();
for (int i = 0; i < chars.length; i++) {
char c = (char) (chars[i] | 0b00100000);
System.out.print(c);
}
}
ch & 0b11011111
即 ch & 0xDF
即 ch & 223
效果:a-z
-> A-Z
,小写字母、小部分标点符号不变。数字和大部分标点符号变成了奇怪的字符。
测试:
public static void main(String[] args) {
String s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz"
+ "1234567890"
+ "[]\\;‘,./"
+ "!@#$%^&*()_+{}|:\"<>?";
char[] chars = s.toCharArray();
for (int i = 0; i < chars.length; i++) {
char c = (char) (chars[i] & 0b11011111);
System.out.print(c);
}
}
ch ^ 32
效果:a-z
-> A-Z
,A-Z
-> a-z
。数字和大部分标点符号变成了奇怪的字符。
测试:
public static void main(String[] args) {
String s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz"
+ "1234567890"
+ "[]\\;‘,./"
+ "!@#$%^&*()_+{}|:\"<>?";
char[] chars = s.toCharArray();
for (int i = 0; i < chars.length; i++) {
char c = (char) (chars[i] ^ 32);
System.out.print(c);
}
}
标签:位操作 rar array i++ string 测试 info img har
原文地址:https://www.cnblogs.com/caophoenix/p/13161985.html