This commit is contained in:
Rinjae
2025-09-05 18:57:45 +09:00
commit aacc1a389e
1229 changed files with 167963 additions and 0 deletions
@@ -0,0 +1,35 @@
package com.eactive.eai.util;
public class HexaConverter {
public static final String bytesToHexa(byte[] abyte) {
StringBuilder s = new StringBuilder();
if (abyte == null)
return s.toString();
for (int i = 0; i < abyte.length; i++) {
s.append( Integer.toHexString((abyte[i] & 0xf0) >> 4) )
.append( Integer.toHexString(abyte[i] & 0xf));
}
return s.toString();
}
public static final byte[] hexaToBytes(String hexa) {
if((hexa.length() % 2) != 0) return null;
byte[] bytes = new byte[hexa.length() / 2];
String hexaBytes = null;
for(int i=0; i <bytes.length;i++) {
hexaBytes = hexa.substring(i*2, i*2+2);
int byteBit = Integer.parseInt(hexaBytes, 16);
bytes[i] = (byte)byteBit;
}
return bytes;
}
// public static void main(String[] argv) {
// String str = "TEST\nÇѱÛ";
// String hexStr = HexaConverter.bytesToHexa(str.getBytes());
// System.out.println(hexStr);
// System.out.println(new String(HexaConverter.hexaToBytes(hexStr), Charset.forName("euc-kr") ) );
// System.out.println(new String(HexaConverter.hexaToBytes(hexStr)) );
// }
}