bitwise OR (on array)
问题 I need to perform bitwise OR of two arrays of byte in Java. How can I do so? byte a= new byte[256]; byte b= new byte[256]; byte c; /*it should contain information i.e bitwise OR of a and b */ 回答1: Thats as simple as using the | operator and a loop: public static byte[] byteOr(byte[] a, byte[] b) { int len = Math.min(a.length, b.length); byte[] result = new byte[len]; for (int i=0; i<len; ++i) result[i] = (byte) (a[i] | b[i]) return result; } 回答2: I think your best bet is to use a BitSet .