Java Utililty Methods Hex Calculate

List of utility methods to do Hex Calculate

Description

The list of methods to do Hex Calculate are organized into topic(s).

Method

CharSequencetoHexDump(byte[] buffer, int offset, int length, boolean hex, boolean ascii)
Creates a hexdump-like output for a given data buffer.
return toHexDump(buffer, offset, length, hex, ascii, true, "\n");
StringtoHexDump(byte[] bytes)
Classname / Method Name : CalculationHelper/toHexDump()
StringBuffer sb = new StringBuffer();
for (int i = 0; i < bytes.length; i = i + 16) {
    String hex = Integer.toString(i, 16).toUpperCase();
    if (hex.length() < 4)
        sb.append("0");
    if (hex.length() < 3)
        sb.append("0");
    if (hex.length() < 2)
...
StringtoHexEscape(final int u0)
to Hex Escape
int u = u0;
int len;
final byte[] b = new byte[6];
if (u <= 0x7f) {
    b[0] = (byte) u;
    len = 1;
} else {
    len = 2;
...
StringtoHexFilter(String inAscii)
to Hex Filter
StringBuilder out = new StringBuilder();
char[] lChars = inAscii.toCharArray();
for (int i = 0; i < lChars.length; i++) {
    out.append(Integer.toHexString((int) lChars[i]));
    if (i < (lChars.length - 1)) {
        out.append(" "); 
return new String(out);
StringtoHexFromBin(final String binSymbols)
Transform a string of binary symbols to a string of hex symbols
String bits = stripBinaryPrefix(binSymbols);
while ((bits.length() % BITS_PER_HEX_DIGIT) != 0) {
    bits = "0" + bits;
StringBuilder hex = new StringBuilder(bits.length() / BITS_PER_HEX_DIGIT);
for (int i = 0; i < bits.length(); i += BITS_PER_HEX_DIGIT) {
    String bitsToAdd = null;
    if ((i + BITS_PER_HEX_DIGIT) < bits.length()) {
...
StringBuildertoHexFromByte(byte b)
Converts byte to hex string.
byte leftSymbol = (byte) (b >>> 4 & 0xF);
byte rightSymbol = (byte) (b & 0xF);
return new StringBuilder(hexSymbols[leftSymbol] + hexSymbols[rightSymbol]);
StringtoHexFromByte(final byte b)
Takes the given input and returns a String containing the hex representation of the byte.
byte leftSymbol = (byte) ((b >>> BITS_PER_HEX_DIGIT) & 0x0f);
byte rightSymbol = (byte) (b & 0x0f);
return (hexSymbols[leftSymbol] + hexSymbols[rightSymbol]);
StringBuildertoHexFromBytes(byte[] bytes)
Converts array of bytes
StringBuilder hexBuilder = null;
if ((bytes != null) && (bytes.length > 0)) {
    hexBuilder = new StringBuilder(bytes.length * 2);
    for (int i = 0; i < bytes.length; i++) {
        hexBuilder.append(toHexFromByte(bytes[i]));
} else {
    hexBuilder = new StringBuilder("");
...
StringtoHexFromBytes(final byte[] bytes)
Takes the given input and returns a String containing the hex representation of the bytes.
if (bytes == null || bytes.length == 0) {
    return ("");
StringBuilder hexBuffer = new StringBuilder(bytes.length * 2);
for (int i = 0; i < bytes.length; i++) {
    hexBuffer.append(toHexFromByte(bytes[i]));
return (hexBuffer.toString());
...
StringtoHexFromOct(final String octSymbols)
Given a String of octal digits, convert them to hex representation
return (toHexFromBin(toBinFromOct(octSymbols)));