Here you can find the source of toHexDec(byte[] bytes)
Parameter | Description |
---|---|
bytes | bytes to format |
public static String toHexDec(byte[] bytes)
//package com.java2s; /*//from www. j ava 2 s .com Calimero - A library for KNX network access Copyright (C) 2006-2008 W. Kastner This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ public class Main { /** * Format first 200 bytes into hex, followed by decimal presentation. * <p> * * @param bytes bytes to format * @return formatted bytes as string */ public static String toHexDec(byte[] bytes) { final StringBuffer buf = new StringBuffer(); final int max = Math.min(200, bytes.length); for (int i = 0; i < max; ++i) { final String hex = Integer.toHexString(bytes[i] & 0xff); if (hex.length() == 1) buf.append("0"); buf.append(hex); buf.append(" "); } if (max < bytes.length) buf.append("..."); buf.append("("); for (int i = 0; i < max; ++i) { final String no = Integer.toString(bytes[i] & 0xff); buf.append(no); if (i < bytes.length - 1) buf.append(" "); } if (max < bytes.length) buf.append("..."); buf.append(")"); return buf.toString(); } }