Java Byte to Hex String byteToHexString(byte value)

Here you can find the source of byteToHexString(byte value)

Description

byte To Hex String

License

Apache License

Declaration

public static String byteToHexString(byte value) 

Method Source Code

//package com.java2s;
/*//from  w ww . j  av  a2  s .  c  o m
 * Copyright 2004,2004 The Apache Software Foundation.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    public static String byteToHexString(byte value) {
        String temp = null;

        switch ((value & 0xF0) >> 4) {
        case 0:
            temp = "0";
            break;
        case 1:
            temp = "1";
            break;
        case 2:
            temp = "2";
            break;
        case 3:
            temp = "3";
            break;
        case 4:
            temp = "4";
            break;
        case 5:
            temp = "5";
            break;
        case 6:
            temp = "6";
            break;
        case 7:
            temp = "7";
            break;
        case 8:
            temp = "8";
            break;
        case 9:
            temp = "9";
            break;
        case 10:
            temp = "A";
            break;
        case 11:
            temp = "B";
            break;
        case 12:
            temp = "C";
            break;
        case 13:
            temp = "D";
            break;
        case 14:
            temp = "E";
            break;
        case 15:
            temp = "F";
            break;
        }
        switch ((value & 0x0F)) {
        case 0:
            temp += "0";
            break;
        case 1:
            temp += "1";
            break;
        case 2:
            temp += "2";
            break;
        case 3:
            temp += "3";
            break;
        case 4:
            temp += "4";
            break;
        case 5:
            temp += "5";
            break;
        case 6:
            temp += "6";
            break;
        case 7:
            temp += "7";
            break;
        case 8:
            temp += "8";
            break;
        case 9:
            temp += "9";
            break;
        case 10:
            temp += "A";
            break;
        case 11:
            temp += "B";
            break;
        case 12:
            temp += "C";
            break;
        case 13:
            temp += "D";
            break;
        case 14:
            temp += "E";
            break;
        case 15:
            temp += "F";
            break;
        }
        return temp;
    }
}

Related

  1. byteToHexString(byte data)
  2. byteToHexString(byte ib)
  3. byteToHexString(byte in)
  4. byteToHexString(byte num)
  5. byteToHexString(byte src)
  6. byteToHexString(byte value)
  7. byteToHexString(byte[] b)
  8. byteToHexString(byte[] b)
  9. byteToHexString(byte[] bytes)