/* P51 位运算符 实例11(& | ~ ^ << >> >>>) 2020年3月13日 16:21:25
*用户创建完新账户后,服务器为保护用户隐私,使用异或运算对用户密码进行二次加密,计算公式为"加密数据=原始密码^加密算子",已知加密算子为整数79,
*用户密码459137经过加密后的值为多少?
*/
public class Bef_Encryption {
public static void main(String[] args) {
int operator = 79;// 声明int型变量operator(算子),并赋初值
int password = 459137;// 声明int形变量password(密码),并赋初值
int newPassword = (password ^ operator);// 加密算法
System.out.println(password + "经过算子:" + operator + "加密后的值为:" + newPassword);
}
}
/*
public class Encryption {
public static void main(String[] args) {
int encryptOperator = 79;
int password = 459137;
int encryptResult = password ^ encryptOperator;
System.out.println("用户密码459137经过加密后的值 = " + encryptResult);
}
}
小结: 第9行代码单一运算关系没必要用括号括起来.没有优先顺序,所以没意义
*/
学习笔记_位移运算
最新推荐文章于 2021-10-28 10:49:41 发布