How it works...
First, we will look at how the script works to separate the R, G, and B values. We first trim the hexadecimal string to exclude the # in case there is one. We need the last six characters of the string. Therefore, we use PowerShell to begin the substring at 1 in case there is a # and 0 in case the string is six characters long. We then pick two characters at a time, starting at 0 (of the trimmed string), 2, and 4.
The conversion happens at the last line. First, we instruct PowerShell that we would like an integer output using the cast operator. Then, we tell PowerShell that the string is a hexadecimal string by adding 0x to its beginning.
This is a simple way of converting a hexadecimal into an integer. Next, we will look ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access