Updated on 2026-08-14

This commit is contained in:
Tangem 2018-05-30 14:05:11 +03:00
parent 8a0b654663
commit 7ab858de77
20 changed files with 129 additions and 133 deletions

View 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;
}
}

View file

@ -0,0 +1,44 @@
package com.tangem.util;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
/**
* Created by Ilia on 15.02.2018.
*/
public class FormatUtil {
public static long parseValue(String valueStr) throws NumberFormatException {
return new BigDecimal(valueStr).multiply(BigDecimal.valueOf(1_0000_0000)).setScale(0, BigDecimal.ROUND_HALF_DOWN).longValueExact();
}
public static String DoubleToString(double amount) {
DecimalFormat myFormatter = GetDecimalFormat();
String output = myFormatter.format(amount);
return output;
}
public static DecimalFormat GetDecimalFormat() {
DecimalFormatSymbols symbols = new DecimalFormatSymbols();
symbols.setDecimalSeparator('.');
String pattern = "#0.######";
DecimalFormat myFormatter = new DecimalFormat(pattern, symbols);
myFormatter.setParseBigDecimal(true);
return myFormatter;
}
public static long ConvertStringToLong(String caption) throws Exception {
BigDecimal d = new BigDecimal(caption);
d = d.multiply(new BigDecimal(100000));
d = d.setScale(5);
BigInteger b = d.toBigInteger();
long l = b.longValue();
return l;
}
}