Java Binary to Hex binaryToHex(int binary)

Here you can find the source of binaryToHex(int binary)

Description

binary To Hex

License

Apache License

Declaration

public static char binaryToHex(int binary) 

Method Source Code

//package com.java2s;
/*/*from  w w  w  .  j av a 2  s.  c  o m*/
 * Copyright (C) 2012 www.amsoft.cn
 * 
 * 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 char binaryToHex(int binary) {
        char ch = ' ';
        switch (binary) {
        case 0:
            ch = '0';
            break;
        case 1:
            ch = '1';
            break;
        case 2:
            ch = '2';
            break;
        case 3:
            ch = '3';
            break;
        case 4:
            ch = '4';
            break;
        case 5:
            ch = '5';
            break;
        case 6:
            ch = '6';
            break;
        case 7:
            ch = '7';
            break;
        case 8:
            ch = '8';
            break;
        case 9:
            ch = '9';
            break;
        case 10:
            ch = 'a';
            break;
        case 11:
            ch = 'b';
            break;
        case 12:
            ch = 'c';
            break;
        case 13:
            ch = 'd';
            break;
        case 14:
            ch = 'e';
            break;
        case 15:
            ch = 'f';
            break;
        default:
            ch = ' ';
        }
        return ch;
    }
}

Related

  1. binaryString2hexString(String bString)
  2. binaryToHex(byte[] ba)
  3. binaryToHex(byte[] bytes)
  4. binaryToHex(byte[] data)
  5. binaryToHex(char[] binaryStr)
  6. BinaryToHexString(byte[] bytes)
  7. binaryToHexString(String binaryValue)
  8. binToHex(byte[] bin)
  9. binToHex(byte[] bytes)