Tech Tip: Utility method to convert RGB color from hexadecimal to RGB integer value
PRODUCT: 4D | VERSION: 20 | PLATFORM: Mac & Win
Published On: November 27, 2023
The utility method below can be used to convert an RGB color from hexadecimal format to integer format:
// Hexadecimal RGB Integer Method // converts an RGB value from hexadecimal color format (#000000) to RGB integer format // "#000000" format refers to hexadecimal color code // "0x00000000" format refers to general hexadecimal number // declare parameters #DECLARE($rgbColorHex : Text)->$rgbInt : Integer // declare variables var $input; $output; $rgbHexNum : Text // change from "#000000" to "0x00000000" format $rgbHexNum:="0x00"+Replace string($rgbColorHex; "#"; "") // insert into 4DTEXT transformation tag + process tag $input:="<!--#4DTEXT "+$rgbHexNum+"-->" PROCESS 4D TAGS($input; $output) // convert resulting string to integer value $rgbInt:=Num($output) |
Here is an example code snippet using this method:
// Test Method // declare variables var $redHex; $customHex : Text var $redInt; $customInt : Integer // red color $redHex:="#FF0000" $redInt:=RGBHextToInt($redHex) // custom color (lime green) $customHex:="#8FFF42" $customInt:=RGBHextToInt($customHex) |