Conversion Results
Conversion Formulas (Simplified)
Brightness & Saturation Adjustments
Color Distribution (RGB)
Sample HEX Colors
Color | HEX |
---|---|
#FF0000 | |
#00FF00 | |
#0000FF | |
#FFFF00 | |
#FF00FF | |
#00FFFF | |
#808080 | |
#800000 | |
#008000 | |
#808000 |
1. HEX to RGB Conversion
Formula
HEX is a 6-digit hexadecimal value representing red, green, and blue (R, G, B). Each pair of digits corresponds to a value between 0-255
.
Split the HEX code into pairs:
- First two characters = Red (
R
) - Next two characters = Green (
G
) - Last two characters = Blue (
B
)
- First two characters = Red (
Convert each pair from hexadecimal (base-16) to decimal (base-10).
Example
HEX Code: #4CAF50
Split into pairs:
- Red =
4C
- Green =
AF
- Blue =
50
- Red =
Convert to decimal:
4C
→ ( 4 \times 16 + 12 = 76 )AF
→ ( 10 \times 16 + 15 = 175 )50
→ ( 5 \times 16 + 0 = 80 )
Result: RGB(76, 175, 80)
2. RGB to HSL Conversion
Formula
HSL stands for Hue, Saturation, and Lightness:
- Hue (H): Angle on the color wheel (0° to 360°).
- Saturation (S): Intensity of the color (0% to 100%).
- Lightness (L): Brightness of the color (0% to 100%).
Steps:
Normalize RGB values to a range of 0-1:
( R{norm} = R/255, \, G{norm} = G/255, \, B_{norm} = B/255 )Calculate max and min values:
( \text{max} = \max(R{norm}, G{norm}, B{norm}) )
( \text{min} = \min(R{norm}, G{norm}, B{norm}) )Compute Lightness (L):
( L = (\text{max} + \text{min}) / 2 )Compute Saturation (S):
- If ( \text{max} = \text{min} ), ( S = 0 ) (grayscale).
- Otherwise,
( S = \frac{\text{max} - \text{min}}{1 - |2L - 1|} )
Compute Hue (H):
- If ( \text{max} = R{norm} ):
( H = 60 \times ((G{norm} - B_{norm}) / (\text{max} - \text{min})) + 360 ) (mod 360) - If ( \text{max} = G{norm} ):
( H = 60 \times ((B{norm} - R_{norm}) / (\text{max} - \text{min})) + 120 ) - If ( \text{max} = B{norm} ):
( H = 60 \times ((R{norm} - G_{norm}) / (\text{max} - \text{min})) + 240 )
- If ( \text{max} = R{norm} ):
Example
RGB: ( (76, 175, 80) )
Normalize:
( R{norm} = 76 / 255 = 0.298, \, G{norm} = 175 / 255 = 0.686, \, B_{norm} = 80 / 255 = 0.314 )Max = 0.686, Min = 0.298
( L = (0.686 + 0.298) / 2 = 0.492 )Saturation: ( S = \frac{0.686 - 0.298}{1 - |2 \times 0.492 - 1|} = 0.579 ) (57.9%)
Hue: ( H = 60 \times \frac{(0.686 - 0.314)}{0.686 - 0.298} + 360 ) (mod 360)
( H = 123° )
Result: HSL(123°, 57.9%, 49.2%)
3. RGB to CMYK Conversion
Formula
CMYK stands for Cyan, Magenta, Yellow, and Key (Black). The formula converts RGB into percentages for printing.
Steps:
Normalize RGB to a 0-1 range:
( R{norm} = R/255, \, G{norm} = G/255, \, B_{norm} = B/255 )Compute Key (K):
( K = 1 - \max(R{norm}, G{norm}, B_{norm}) )Compute Cyan (C), Magenta (M), and Yellow (Y):
- ( C = \frac{1 - R_{norm} - K}{1 - K} )
- ( M = \frac{1 - G_{norm} - K}{1 - K} )
- ( Y = \frac{1 - B_{norm} - K}{1 - K} )
If ( K = 1 ), then ( C = M = Y = 0 ).
Example
RGB: ( (76, 175, 80) )
Normalize:
( R{norm} = 76 / 255 = 0.298, \, G{norm} = 175 / 255 = 0.686, \, B_{norm} = 80 / 255 = 0.314 )Compute Key (K):
( K = 1 - \max(0.298, 0.686, 0.314) = 0.314 )Compute Cyan (C):
( C = \frac{1 - 0.298 - 0.314}{1 - 0.314} = 0.702 ) (70.2%)Compute Magenta (M):
( M = \frac{1 - 0.686 - 0.314}{1 - 0.314} = 0.000 ) (0%)Compute Yellow (Y):
( Y = \frac{1 - 0.314 - 0.314}{1 - 0.314} = 0.500 ) (50%)
Result: CMYK(70.2%, 0%, 50%, 31.4%)
Summary Table of Example Conversions
HEX | RGB | HSL | CMYK |
---|---|---|---|
#4CAF50 |
RGB(76, 175, 80) | HSL(123°, 57.9%, 49.2%) | CMYK(70.2%, 0%, 50%, 31.4%) |
This step-by-step breakdown helps you to understand exactly how your HEX color codes are converted into other formats!
0 Comments