Java Hex Calculate toHexString3(byte aByte)

Here you can find the source of toHexString3(byte aByte)

Description

to Hex String

License

Creative Commons License

Declaration

public static String toHexString3(byte aByte) 

Method Source Code

//package com.java2s;
/*// ww w .j  ava  2s.  c  om
 * This file is part of the NetFef serial network bus protocol project.
 *
 * Copyright (c) 2015.
 * Author: Balazs Kelemen
 * Contact: prampec+netfef@gmail.com
 *
 * This product is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) license.
 * Please contact the author for a special agreement in case you want to use this creation for commercial purposes!
 */

public class Main {
    public static String toHexString3(byte aByte) {
        String str = Integer.toHexString(byteToInt(aByte));
        String s = str.length() == 1 ? "0x0" + str : "0x" + str;
        return s;

    }

    public static String toHexString(byte aByte) {
        String str = Integer.toHexString(byteToInt(aByte));
        String s = str.length() == 1 ? "0" + str : str;
        if ((aByte >= ' ') && (aByte <= '~')) {
            s = s + "(" + (char) aByte + ")";
        }
        return s;

    }

    public static int byteToInt(byte aByte) {
        return aByte & 0xFF;
    }
}

Related

  1. toHexString(String str)
  2. toHexString(String str)
  3. toHexString(StringBuffer buffer, byte[] bytes, int numBytes)
  4. toHexString0x(byte[] byteArray)
  5. toHexString2(int i)
  6. toHexStringBE(char[] array)
  7. toHexStringLE(byte n)
  8. toHexStringUpperCase(byte[] b)
  9. toHexTable(byte[] byteSrc, int lengthOfLine)