Java Hex Calculate toHexString2(int i)

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

Description

to Hex String

License

Open Source License

Declaration

protected static String toHexString2(int i) 

Method Source Code

//package com.java2s;
/*/*from ww w.ja v a2s. c o m*/
 * This file is part of the Jose Project
 * see http://jose-chess.sourceforge.net/
 * (c) 2002-2006 Peter Sch?fer
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 */

public class Main {
    protected static String toHexString2(int i) {
        String zeros = "00000000000";
        String hex = Integer.toHexString(i);
        int len = hex.length();
        if (len < 2)
            return zeros.substring(0, 2 - len) + hex;
        else
            return hex.substring(0, 2);
    }

    protected static String toHexString(int i) {
        String zeros = "00000000000";
        String hex = Integer.toHexString(i);
        int len = hex.length();
        if (len < 4)
            return zeros.substring(0, 4 - len) + hex;
        else
            return hex;
    }
}

Related

  1. toHexString(String s)
  2. toHexString(String str)
  3. toHexString(String str)
  4. toHexString(StringBuffer buffer, byte[] bytes, int numBytes)
  5. toHexString0x(byte[] byteArray)
  6. toHexString3(byte aByte)
  7. toHexStringBE(char[] array)
  8. toHexStringLE(byte n)
  9. toHexStringUpperCase(byte[] b)