Java Hex Calculate toHex(int r, int g, int b)

Here you can find the source of toHex(int r, int g, int b)

Description

to Hex

License

Mozilla Public License

Declaration

public static String toHex(int r, int g, int b) 

Method Source Code

//package com.java2s;
/**//  w  ww  .j  a  va2s .c o  m
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This Source Code Form is "Incompatible With Secondary Licenses", as
 * defined by the Mozilla Public License, v. 2.0.
 */

public class Main {
    public static String toHex(int r, int g, int b) {
        return "#" + toBrowserHexValue(r) + toBrowserHexValue(g) + toBrowserHexValue(b);
    }

    private static String toBrowserHexValue(int number) {
        StringBuilder builder = new StringBuilder(Integer.toHexString(number & 0xff));
        while (builder.length() < 2) {
            builder.append("0");
        }
        return builder.toString().toUpperCase();
    }
}

Related

  1. toHex(int nibble)
  2. toHex(int num)
  3. toHex(int nybble)
  4. toHex(int r, int g, int b)
  5. toHex(int r, int g, int b)
  6. toHex(int v)
  7. toHex(int val)
  8. toHex(int val)
  9. toHex(int value)