数据的奇偶校验
/**
* 数据的奇偶校验
*
*/
public static int Number(String str) {
//先将字符转成2进制
String str1 = "";
char[] strChar = str1.toCharArray();
String result = "";
for (int i = 0; i < strChar.length; i++) {
result += Integer.toBinaryString(strChar[i]) + " ";
}
//循环找出二进制数字中1的个数
int a1 = 0;
for (int i = 0; i < result.length(); i++) {
String c = result.substring(i, i + 1);
if (c.equalsIgnoreCase("1")) {
a1++;
}
}
int b = a1 % 2 == 0 ? 0 : 1;
return b;
}