Java Hex Calculate toHexByte(int i)

Here you can find the source of toHexByte(int i)

Description

Converts an integer to a 2-digit hexadecimal string.

License

Apache License

Parameter

Parameter Description
i a parameter

Declaration

public static String toHexByte(int i) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//from w ww .  j a v a2 s .  c o m
     * Converts an integer to a 2-digit hexadecimal string. i.e. 0 -> 00, 11 -> 0b, 255 -> ff
     * i must fall inside 0 and 255 inclusive.
     * @param i
     * @return
     */
    public static String toHexByte(int i) {
        assert (i >= 0 && i < 256);
        String s = Integer.toString(i, 16);
        if (s.length() < 2)
            return "0" + s;
        return s;
    }
}

Related

  1. toHexaString(int value)
  2. toHexByte(byte b)
  3. toHexByte(byte b, StringBuffer sb)
  4. toHexByte(final char ch1, final char ch2)
  5. toHexByte(int bite)
  6. toHexByteArray(final byte[] buffer)
  7. toHexBytes(byte[] bytes)
  8. toHexBytes(byte[] data)
  9. toHexBytes(byte[] toBeConverted)