Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
听说这是一个面试问的问题,给定两个字节,如果对称则返回true
public boolean isSym(Byte firstByte, Byte secondByte);
01101000 和 00010110 是对称的,但 01100000 和 11000000 不是对称的。需要用Java编写代码。有什么想法最好的方法是什么?
public boolean isSym(Byte firstByte, Byte secondByte) { for (int i = 0; i< 8 ; i++){ if (bitAt(firstByte, i) != bitAt(secondByte, 7 - i)) return false; } return true; } public byte bitAt(byte num, int position) { return (byte)((num >> position) & (byte)1); }