Java Char to Hex char2Hex(char c)

Here you can find the source of char2Hex(char c)

Description

char Hex

License

Open Source License

Declaration

static public String char2Hex(char c) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    static public String char2Hex(char c) {
        // Returns hex String representation of char c
        byte hi = (byte) (c >>> 8);
        byte lo = (byte) (c & 0xff);
        return byte2Hex(hi) + byte2Hex(lo);
    }//from ww  w  .  j  av a2 s. c  o  m

    static public String byte2Hex(byte b) {
        // Returns hex String representation of byte b
        final char hexDigit[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
        char[] array = { hexDigit[(b >> 4) & 0x0f], hexDigit[b & 0x0f] };
        return new String(array);
    }
}

Related

  1. charToHex(char c)
  2. charToHex(char c)
  3. charToHex(char c)
  4. charToHexdigit(final byte c)