HEX to RGB

HEX Input
Sample
RGB Output

HEX to RGB Converter

The HEX to RGB converter is a simple online tool that allows you to convert HEX color codes to RGB color codes quickly and easily. This tool is free to use, requires no system or software dependencies, and is mobile-friendly.

Features

  • Online and free, no system or software dependencies
  • Can Clear, Can Copy, Have Sample
  • Data security, local computing

How to Use the HEX to RGB Converter

  1. Input or paste HEX color codes like #ffd500 into the input field.
  2. Click the "Convert" button to convert the HEX code into its corresponding RGB value.
  3. Copy the converted RGB code to your clipboard by clicking the "Copy" button.

Benefits and Advantages of Using the HEX to RGB Converter

  • Saves time and effort in color matching or manipulation tasks.
  • Ensures accuracy and consistency in color usage across different applications.
  • Eliminates the need for manual conversion between color code formats.
  • Can be used for web design, graphic design, digital art, and other creative industries.

Core Algorithm

The HEX to RGB conversion formula is as follows:

R = hexToInt(hex.substring(1, 3));
G = hexToInt(hex.substring(3, 5));
B = hexToInt(hex.substring(5, 7));
rgb = "rgb(" + R + ", " + G + ", " + B + ")";

Code Examples

Python

def hex_to_rgb(hex):
    r = int(hex[1:3], 16)
    g = int(hex[3:5], 16)
    b = int(hex[5:7], 16)
    return (r, g, b)

print(hex_to_rgb("#ffd500")) # Output: (255, 213, 0)

C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

void hex_to_rgb(char *hex, int *r, int *g, int *b) {
    *r = (int)strtol(&hex[1], NULL, 16);
    *g = (int)strtol(&hex[3], NULL, 16);
    *b = (int)strtol(&hex[5], NULL, 16);
}

int main() {
    char hex[] = "#ffd500";
    int r, g, b;

    hex_to_rgb(hex, &r, &g, &b);

    printf("RGB(%d, %d, %d)", r, g, b); // Output: RGB(255, 213, 0)

    return 0;
}

JavaScript

function hexToRgb(hex) {
  const r = parseInt(hex.substring(1, 3), 16);
  const g = parseInt(hex.substring(3, 5), 16);
  const b = parseInt(hex.substring(5, 7), 16);
  return `rgb(${r}, ${g}, ${b})`;
}

console.log(hexToRgb("#ffd500")); // Output: rgb(255, 213, 0)

Java

public static int[] hexToRgb(String hex) {
    int r = Integer.parseInt(hex.substring(1, 3), 16);
    int g = Integer.parseInt(hex.substring(3, 5), 16);
    int b = Integer.parseInt(hex.substring(5, 7), 16);
    return new int[]{ r, g, b };
}

public static void main(String[] args) {
    String hex = "#ffd500";
    int[] rgb = hexToRgb(hex);
    System.out.printf("RGB(%d, %d, %d)", rgb[0], rgb[1], rgb[2]); // Output: RGB(255, 213, 0)
}

PHP

function hexToRgb($hex) {
  $r = hexdec(substr($hex, 1, 2));
  $g = hexdec(substr($hex, 3, 2));
  $b = hexdec(substr($hex, 5, 2));
  return "rgb($r, $g, $b)";
}

echo hexToRgb("#ffd500"); // Output: rgb(255, 213, 0)

In conclusion, the HEX to RGB converter is a useful tool for anyone who needs to convert HEX color codes to RGB color codes. It is easy to use, free, and mobile-friendly, making it a great choice for web designers, graphic designers, and anyone else who needs to work with colors.

Frequently Asked Questions (FAQ)

Meet our more Tools