Java Hex Calculate tohex(byte b)

Here you can find the source of tohex(byte b)

Description

tohex

License

Apache License

Declaration

private static String tohex(byte b) 

Method Source Code

//package com.java2s;
/*//w  ww. j  a  va2  s .  c o  m
 * Copyright 2013 Krzysztof Otrebski (otros.systems@gmail.com)
 *
 * 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 {
    private static String tohex(byte b) {
        if (b == 0)
            return "0";
        else if (b == 1)
            return "1";
        else if (b == 2)
            return "2";
        else if (b == 3)
            return "3";
        else if (b == 4)
            return "4";
        else if (b == 5)
            return "5";
        else if (b == 6)
            return "6";
        else if (b == 7)
            return "7";
        else if (b == 8)
            return "8";
        else if (b == 9)
            return "9";
        else if (b == 10)
            return "a";
        else if (b == 11)
            return "b";
        else if (b == 12)
            return "c";
        else if (b == 13)
            return "d";
        else if (b == 14)
            return "e";
        else if (b == 15)
            return "f";
        throw new IllegalArgumentException("we should never be here");
    }
}

Related

  1. toHex(boolean[] bits)
  2. toHex(byte b)
  3. toHex(byte b)
  4. toHex(byte b)
  5. toHex(byte b)
  6. toHex(byte b)
  7. toHex(byte b)
  8. toHex(byte b)