Here you can find the source of toHexDump(byte[] bytes)
Parameter | Description |
---|---|
bytes | a parameter |
public static String toHexDump(byte[] bytes)
//package com.java2s; //License from project: Apache License public class Main { /**/*from w w w.j a v a2 s. c o m*/ * * Classname / Method Name : CalculationHelper/toHexDump() * * @param bytes * @return * @Description : Method is used to Create HEX dump of input byte array */ public static String toHexDump(byte[] bytes) { 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) sb.append("0"); sb.append(hex + "\t"); int j; for (j = i; j < i + 16 && j < bytes.length; j++) { hex = Integer.toString(bytes[j] & 0xff, 16).toUpperCase(); if (hex.length() == 1) { hex = "0" + hex; } sb.append(hex + " "); } // fill out row if (j - i < 16) { for (int k = 0; k < 16 - (j - i); k++) { sb.append(" "); } } sb.append("\t"); for (j = i; j < i + 16 && j < bytes.length; j++) { if (bytes[j] < 32 || bytes[j] > 126) { sb.append("."); } else { sb.append((char) bytes[j]); } } sb.append("\n"); } return sb.toString(); } }