Created
July 13, 2018 11:59
-
-
Save deldersveld/1769850fd055a1c978544d1e0ff0cd60 to your computer and use it in GitHub Desktop.
DAX - RGB Decimal Color to Hex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RGB Decimal Color to Hex = | |
// Manually enter components of RGB decimal color value, e.g. "RGB(1,184,170)" | |
VAR RedDecimalColorValue = 1 | |
VAR GreenDecimalColorValue = 184 | |
VAR BlueDecimalColorValue = 170 | |
//Decimal to Hex | |
VAR RedPosition0Dec = MOD(RedDecimalColorValue,16) | |
VAR RedPosition0Div = INT(RedDecimalColorValue / 16) | |
VAR RedPosition1Dec = MOD(RedPosition0Div,16) | |
VAR RedPosition1Div = INT(RedPosition0Div / 16) | |
VAR GreenPosition0Dec = MOD(GreenDecimalColorValue,16) | |
VAR GreenPosition0Div = INT(GreenDecimalColorValue / 16) | |
VAR GreenPosition1Dec = MOD(GreenPosition0Div,16) | |
VAR GreenPosition1Div = INT(GreenPosition0Div / 16) | |
VAR BluePosition0Dec = MOD(BlueDecimalColorValue,16) | |
VAR BluePosition0Div = INT(BlueDecimalColorValue / 16) | |
VAR BluePosition1Dec = MOD(BluePosition0Div,16) | |
VAR BluePosition1Div = INT(BluePosition0Div / 16) | |
VAR RedPosition0Hex = SWITCH(RedPosition0Dec,10,"A",11,"B",12,"C",13,"D",14,"E",15,"F",RedPosition0Dec) | |
VAR RedPosition1Hex = SWITCH(RedPosition1Dec,10,"A",11,"B",12,"C",13,"D",14,"E",15,"F",RedPosition1Dec) | |
VAR GreenPosition0Hex = SWITCH(GreenPosition0Dec,10,"A",11,"B",12,"C",13,"D",14,"E",15,"F",GreenPosition0Dec) | |
VAR GreenPosition1Hex = SWITCH(GreenPosition1Dec,10,"A",11,"B",12,"C",13,"D",14,"E",15,"F",GreenPosition1Dec) | |
VAR BluePosition0Hex = SWITCH(BluePosition0Dec,10,"A",11,"B",12,"C",13,"D",14,"E",15,"F",BluePosition0Dec) | |
VAR BluePosition1Hex = SWITCH(BluePosition1Dec,10,"A",11,"B",12,"C",13,"D",14,"E",15,"F",BluePosition1Dec) | |
VAR RGBDecimalColorAsHex = "#" & RedPosition1Hex & RedPosition0Hex & GreenPosition1Hex & GreenPosition0Hex & BluePosition1Hex & BluePosition0Hex | |
RETURN RGBDecimalColorAsHex |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment