Java Hex Calculate toHexString(int n)

Here you can find the source of toHexString(int n)

Description

to Hex String

License

Open Source License

Declaration

public static String toHexString(int n) 

Method Source Code

//package com.java2s;
/*/*from   w w w .j av a 2s  .  c om*/
 *  This file is part of easyFPGA.
 *  Copyright 2013-2015 os-cillation GmbH
 *
 *  easyFPGA 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 3 of the License, or
 *  (at your option) any later version.
 *
 *  easyFPGA is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with easyFPGA.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

public class Main {
    public static String toHexString(int n) {
        return String.format("0x%8s", Integer.toHexString(n)).replace(' ', '0').toUpperCase();
    }

    public static String toHexString(byte[] byteStream) {
        String output = "";
        for (byte b : byteStream) {
            output += String.format("%02X ", b);
        }
        return output;
    }

    public static String toHexString(int[] byteStream) {
        String output = "";
        for (int i : byteStream) {
            output += String.format("%02X ", i & 0xFF);
        }
        return output;
    }
}

Related

  1. toHexString(int i)
  2. toHexString(int i)
  3. toHexString(int i, int digits)
  4. toHexString(int input)
  5. toHexString(int iValue)
  6. toHexString(int number, int digit)
  7. toHexString(int r, int g, int b, int a)
  8. toHexString(int val)
  9. toHexString(int val, int minLength)