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.
これはインタビューで尋ねられた質問だと聞きました.2バイトが与えられた場合、それらが対称であれば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); }