Let the computer do the work. What about this?
Code: Select all
Procedure.s RGB2Hex(R.l,G.l,B.l)
ProcedureReturn Hex(Red(RGB(R,G,B)))+Hex(Green(RGB(R,G,B)))+Hex(Blue(RGB(R,G,B)))
EndProcedure
Debug RGB2Hex(36,104,160)
OR
Code: Select all
Procedure.s RGB2Hex(RGB.l)
ProcedureReturn Hex(Red(RGB))+Hex(Green(RGB))+Hex(Blue(RGB))
EndProcedure
Debug RGB2Hex(RGB(36,104,160))
OR (if you want the leading "0")
Code: Select all
Procedure.s RGB2Hex(RGB.l)
ProcedureReturn RSet(Hex(Red(RGB)),2,"0")+RSet(Hex(Green(RGB)),2,"0")+RSet(Hex(Blue(RGB)),2,"0")
EndProcedure
Debug RGB2Hex(RGB(12,4,16))
It is true the output of RGB() does reverse the input. This is why this
Hex(RGB(32, 23, 30)) doesn't work like you want. It is not Hex()'s fault, it is correctly translating the output of RGB().
Code: Select all
Debug RGB(36,104,160)
Debug Bin(RGB(36,104,160))
10512420
1010 0000 0110 1000 0010 0100
A 0 6 8 2 4