Updated on 2026-08-14
This commit is contained in:
parent
8a0b654663
commit
7ab858de77
20 changed files with 129 additions and 133 deletions
39
app/src/main/java/com/tangem/util/ByteUtil.java
Normal file
39
app/src/main/java/com/tangem/util/ByteUtil.java
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
package com.tangem.util;
|
||||
|
||||
public class ByteUtil {
|
||||
|
||||
public static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
|
||||
public static byte[] and(byte[] b1, byte[] b2) {
|
||||
if (b1.length != b2.length) throw new RuntimeException("Array sizes differ");
|
||||
byte[] ret = new byte[b1.length];
|
||||
for (int i = 0; i < ret.length; i++) {
|
||||
ret[i] = (byte) (b1[i] & b2[i]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static byte[] or(byte[] b1, byte[] b2) {
|
||||
if (b1.length != b2.length) throw new RuntimeException("Array sizes differ");
|
||||
byte[] ret = new byte[b1.length];
|
||||
for (int i = 0; i < ret.length; i++) {
|
||||
ret[i] = (byte) (b1[i] | b2[i]);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static boolean isNullOrZeroArray(byte[] array){
|
||||
return (array == null) || (array.length == 0);
|
||||
}
|
||||
|
||||
public static boolean isSingleZero(byte[] array){
|
||||
return (array.length == 1 && array[0] == 0);
|
||||
}
|
||||
|
||||
public static int length(byte[]... bytes) {
|
||||
int result = 0;
|
||||
for (byte[] array : bytes) {
|
||||
result += (array == null) ? 0 : array.length;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue