Skip to content

Instantly share code, notes, and snippets.

@mattmcnabb
Last active October 5, 2018 03:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattmcnabb/20f4f7aec041801cdca9b01b065c321c to your computer and use it in GitHub Desktop.
Save mattmcnabb/20f4f7aec041801cdca9b01b065c321c to your computer and use it in GitHub Desktop.
function ConvertFrom-RGB
{
param
(
[Parameter(Mandatory)]
[ValidateCount(3,3)]
[Byte[]]
$RGB
)
$Hexes = foreach ($Byte in $RGB)
{
[Convert]::ToString($Byte, 16).ToUpper()
}
"#{0}{1}{2}" -f $Hexes
}
function ConvertTo-Rgb
{
param
(
[parameter(Mandatory)]
[ValidatePattern("^#[A-Fa-f0-9]{6}$")]
[string]
$Hex
)
$null = $Hex -match "^#(?'Byte1'\w{2})(?'Byte2'\w{2})(?'Byte3'\w{2})$"
$Matches.Byte1, $Matches.Byte2, $Matches.Byte3 | foreach {
[Convert]::ToByte($_, 16)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment