Java Hex Calculate toHex(byte b, char[] charArray, int from)

Here you can find the source of toHex(byte b, char[] charArray, int from)

Description

Converts a byte value to hexadecimal and put the result in an array.

License

Open Source License

Parameter

Parameter Description
b the byte value to convert.
charArray the array in which the result is put.
from the array's index to use as a starting point.

Declaration

private static void toHex(byte b, char[] charArray, int from) 

Method Source Code

//package com.java2s;
/**//from   w w  w .j av  a2 s  .  c o m
 * This file is part of emf2gv : an eclipse plugin that allows to
 * generate a graphical representation of an EMF model.
 *
 * Copyright 2010-2011 Jean-Francois Brazeau
 * 
 * emf2gv is free software: you can redistribute it and/or modify
 * it under the terms of either:
 * 
 *      a) the GNU Lesser General Public License as published by
 *       the Free Software Foundation, either version 3 of the License, or
 *       (at your option) any later version.
 *  or
 *      b) the Eclipse Public License version 1.0 as published by
 *       the Eclipse Foundation.
 * 
 * emf2gv 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 Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with emf2gv.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * You should have received a copy of the  Eclipse Public License
 * along with emf2gv.  If not, see <http://www.eclipse.org/legal/epl-v10.html>.
 */

public class Main {
    /** Hex characters */
    private static final char[] c = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C',
            'D', 'E', 'F' };

    /**
     * Converts a byte value to hexadecimal and put the result in an array.
     * 
     * @param b
     *            the byte value to convert.
     * @param charArray
     *            the array in which the result is put.
     * @param from
     *            the array's index to use as a starting point.
     */
    private static void toHex(byte b, char[] charArray, int from) {
        charArray[from] = c[(b >> 4) & 0x0F];
        charArray[from + 1] = c[b & 0x0F];
    }
}

Related

  1. toHex(byte b)
  2. toHex(byte b)
  3. toHex(byte b)
  4. toHex(byte b)
  5. toHex(byte b)
  6. toHex(byte b, String prefix)
  7. toHex(byte bytes[])
  8. toHex(byte data[])
  9. toHex(byte hash[])