Here you can find the source of bytesToText(byte[] bytes)
Parameter | Description |
---|---|
bytes | a parameter |
private static String bytesToText(byte[] bytes)
//package com.java2s; public class Main { /**/*from www .jav a2s . co m*/ * Convert bytes to text * * @param bytes * @return text for the input bytes */ private static String bytesToText(byte[] bytes) { StringBuffer sb = new StringBuffer(bytes.length * 2); for (int i = 0; i < bytes.length; i++) { int num = bytes[i]; if (num < 0) num = 127 + (num * -1); // fix negative back to positive String hex = Integer.toHexString(num); if (hex.length() == 1) { hex = "0" + hex; // ensure 2 digits } sb.append(hex); } return sb.toString(); } }