X-Git-Url: https://git.nmode.ca/signal-cli/blobdiff_plain/f2c2597379280e0aea56932647eded1c5f7cc72c..55d485de88bf2f67f64be3978cf7c5649f1cc36f:/src/main/java/org/asamk/signal/Hex.java diff --git a/src/main/java/org/asamk/signal/Hex.java b/src/main/java/org/asamk/signal/Hex.java new file mode 100644 index 00000000..43d77cc5 --- /dev/null +++ b/src/main/java/org/asamk/signal/Hex.java @@ -0,0 +1,22 @@ +package org.asamk.signal; + +public class Hex { + + private final static char[] HEX_DIGITS = { + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' + }; + + public static String toStringCondensed(byte[] bytes) { + StringBuffer buf = new StringBuffer(); + for (int i = 0; i < bytes.length; i++) { + appendHexChar(buf, bytes[i]); + } + return buf.toString(); + } + + private static void appendHexChar(StringBuffer buf, int b) { + buf.append(HEX_DIGITS[(b >> 4) & 0xf]); + buf.append(HEX_DIGITS[b & 0xf]); + buf.append(" "); + } +}