Here you can find the source of printByteWithChar(byte[] byteArray)
Parameter | Description |
---|---|
byteArray | a parameter |
public static String printByteWithChar(byte[] byteArray)
//package com.java2s; //License from project: Apache License public class Main { /**/*from w w w . ja v a 2 s.c o m*/ * return beautified String of byte array * @param byteArray * @return beautified String of byte array */ public static String printByteWithChar(byte[] byteArray) { int blockSize = 32; StringBuilder sb = new StringBuilder(); StringBuilder sb1 = new StringBuilder(); for (int i = 0; i < byteArray.length; i++) { if (byteArray[i] > 10) { // sb.append(Integer.toHexString(byteArray[i])).append(" "); sb.append(String.format("%02X", byteArray[i])).append(" "); } else { // sb.append(" ").append(Integer.toHexString(byteArray[i])).append(" "); sb.append(" ").append(String.format("%02X", byteArray[i])).append(" "); } if ((blockSize - 1) == (i % blockSize)) { sb.append("\r\n"); } } sb.append("\r\n"); for (int i = 0; i < byteArray.length; i++) { if (byteArray[i] > 10) { sb1.append(" ").append((char) byteArray[i]).append(" "); } else { sb1.append(". ").append(byteArray[i]).append(" "); } if ((blockSize - 1) == (i % blockSize)) { sb1.append("\r\n"); } } return sb.toString() + sb1.toString(); } }