Java Hex Calculate toHexString(byte bytes[])

Here you can find the source of toHexString(byte bytes[])

Description

Converts the checksum given as an array of bytes into a hex-encoded string.

License

Open Source License

Parameter

Parameter Description
bytes The checksum as an array of bytes

Return

The checksum as a hex-encoded string

Declaration

private static String toHexString(byte bytes[]) 

Method Source Code

//package com.java2s;
/**/*  w  w w.j  ava  2s  . c o m*/
 * Project Wonderland
 *
 * Copyright (c) 2004-2009, Sun Microsystems, Inc., All Rights Reserved
 *
 * Redistributions in source code form must reproduce the above
 * copyright and this condition.
 *
 * The contents of this file are subject to the GNU General Public
 * License, Version 2 (the "License"); you may not use this file
 * except in compliance with the License. A copy of the License is
 * available at http://www.opensource.org/licenses/gpl-license.php.
 *
 * Sun designates this particular file as subject to the "Classpath" 
 * exception as provided by Sun in the License file that accompanied 
 * this code.
 */

public class Main {
    /**
     * Converts the checksum given as an array of bytes into a hex-encoded
     * string.
     *
     * @param bytes The checksum as an array of bytes
     * @return The checksum as a hex-encoded string
     */
    private static String toHexString(byte bytes[]) {
        StringBuffer ret = new StringBuffer();
        for (int i = 0; i < bytes.length; ++i) {
            ret.append(Integer.toHexString(0x0100 + (bytes[i] & 0x00FF)).substring(1));
        }
        return ret.toString();
    }
}

Related

  1. toHexString(byte buffer[])
  2. toHexString(byte bytes[])
  3. toHexString(byte bytes[])
  4. toHexString(byte bytes[])
  5. toHexString(byte bytes[])
  6. toHexString(byte bytes[])
  7. toHexString(byte data[])
  8. toHexString(byte input[])
  9. toHexString(byte n)