Java Hex Format FormatAs2CharHexa(byte byValue)

Here you can find the source of FormatAs2CharHexa(byte byValue)

Description

Format As Char Hexa

License

LGPL

Declaration

static public String FormatAs2CharHexa(byte byValue) 

Method Source Code

//package com.java2s;
/*//from   w w  w.ja va  2 s  . co  m
 * JLib - Publicitas Java library v1.2.0.
 *
 * Copyright (c) 2005, 2006, 2007, 2008, 2009 Publicitas SA.
 * Licensed under LGPL (LGPL-LICENSE.txt) license.
 */

public class Main {
    static public String FormatAs2CharHexa(int nValue) {
        String cs = "";
        char c;
        for (int n = 0; n < 2; n++) {
            int nChar = nValue % 16;
            nValue = nValue / 16;
            if (nChar <= 9)
                c = (char) ('0' + nChar);
            else
                c = (char) ('A' + nChar - 10);
            cs = c + cs;
        }
        return cs;
    }

    static public String FormatAs2CharHexa(byte byValue) {
        if (byValue < 0)
            return FormatAs2CharHexa((int) byValue + 256);
        else
            return FormatAs2CharHexa((int) byValue);
    }
}

Related

  1. formatAddress6(int[] hexRepresentation)
  2. FormatAs4CharHexa(int nValue)
  3. formatAsHex(byte[] bytes)
  4. formatAsHex(long msgId)
  5. formatAsHexUppercase(long msgId)