Java Hex Calculate toHex(byte b)

Here you can find the source of toHex(byte b)

Description

Convert a byte to its hexadecimal representation.

License

Open Source License

Parameter

Parameter Description
b the byte value to convert

Return

the representation of b as a pair of hexadecimal digits.

Declaration

public static String toHex(byte b) 

Method Source Code

//package com.java2s;
/*/*from  www. j a v a 2s  .  c  om*/
 * Copyright 2006 Helsinki Institute for Information Technology
 * 
 * This file is a part of Fuego middleware. Fuego middleware is free software; you can redistribute
 * it and/or modify it under the terms of the MIT license, included as the file MIT-LICENSE in the
 * Fuego middleware source distribution. If you did not receive the MIT license with the
 * distribution, write to the Fuego Core project at fuego-core-users@hoslab.cs.helsinki.fi.
 */

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

    /**
     * Convert a byte to its hexadecimal representation.
     * @param b
     *            the byte value to convert
     * @return the representation of <code>b</code> as a pair of hexadecimal digits.
     */
    public static String toHex(byte b) {
        return (new Character(hexDigits[(b & 0xF0) >> 4])).toString() + hexDigits[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, char[] charArray, int from)
  7. toHex(byte b, String prefix)
  8. toHex(byte bytes[])
  9. toHex(byte data[])