Java Hex Calculate toHexChar(int value)

Here you can find the source of toHexChar(int value)

Description

Convert the given value, which must be between 0 and 15, into its equivalent hex character between 0 and F.

License

Apache License

Parameter

Parameter Description
value Integer value between 0 and 15.

Exception

Parameter Description
IllegalArgumentException If the value is out of range.

Return

Equivalent hex character between 0 and F.

Declaration

public static char toHexChar(int value) 

Method Source Code

//package com.java2s;
/*/*w  ww .  j a v  a 2s . c  o m*/
 * Copyright (C) 2014 Dell, Inc.
 * 
 * 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 {
    /**
     * Convert the given value, which must be between 0 and 15, into its equivalent hex
     * character between 0 and F.
     * 
     * @param  value                    Integer value between 0 and 15.
     * @return                          Equivalent hex character between 0 and F.
     * @throws IllegalArgumentException If the value is out of range.
     */
    public static char toHexChar(int value) {
        switch (value) {
        case 0:
            return '0';
        case 1:
            return '1';
        case 2:
            return '2';
        case 3:
            return '3';
        case 4:
            return '4';
        case 5:
            return '5';
        case 6:
            return '6';
        case 7:
            return '7';
        case 8:
            return '8';
        case 9:
            return '9';
        case 10:
            return 'A';
        case 11:
            return 'B';
        case 12:
            return 'C';
        case 13:
            return 'D';
        case 14:
            return 'E';
        case 15:
            return 'F';
        default:
            throw new IllegalArgumentException("Value must be between 0 and 15: " + value);
        }
    }
}

Related

  1. toHexChar(int i)
  2. toHexChar(int i)
  3. toHexChar(int i)
  4. toHexChar(int nibble)
  5. toHexChar(int paramInt)
  6. toHexCharArray(byte[] input)
  7. toHexCharFromBin(final String bin)
  8. toHexChars(byte[] bs)
  9. toHexChars(byte[] bytes)