Convert RGB to decimal

I need to know the values of the RGB color in decimal mode. Anyone knows the equation?(no script) Thanks.

If by decimal mode you mean a 4 dimensional float ranging between 0 and 1 for R, G, B and A values then:

RGB(A) is a 256-bit color, so by that logic then any channel can be 0 to 255. Knowing this, we can say a color is 255(r),127(g),25(b),255(a) you can do this:

Color color = new Color(r/255.0F,g/255.0F,b/255.0F,a/255.0F);

The equation is very basic math. 0 is 0 and 255 is 1, you simply take the number of bits in that channel and divide it by the maximum (255) to find it’s normalized (decimal) value.

EDIT - Note: As Mike mentioned, don’t divide by an int and expect to get a float. Always divide by a float to get decimal values.

Hope that helps


You can use the following function.

exampel for red:
private Color32 ColorRed = new Color32(255, 0, 0, 255);

Or you can use this:

and totally skip equations and scripts.

Well, there is really no way to do what you say without script. What is decimal mode exactly? Do you want to get one of the r g or b values?

Also there is a web converter

after can use directly

Color color = new Color(0,5f,0.5f,0.5f, 1f);
// values from that converter enter here.