Why do computer nerds mix up Halloween and Christmas? Because 31 OCT = 25 DEC :)

I always mix up the commands used to convert integers to and from decimal, hexadecimal and octal in Powershell. That’s why I wrote these functions and put them in my profile:

# Description: Coverts a decimal into a hexadecimal

function Convert-DECtoHEX
{
param($DEC)
ForEach ($value in $DEC)
{
“{0:x}” -f [Int]$value
}
}

# Description: Coverts a hexadecimal into a decimal

function Convert-HEXtoDEC
{
param($HEX)
ForEach ($value in $HEX)
{
[Convert]::ToInt32($value,16)
}
}

# Description: Coverts an octal into a decimal

function Convert-OCTtoDEC
{
param($OCT)
ForEach ($value in $OCT)
{
[Convert]::ToInt32($value,8)
}
}

Here are some example uses:
2009-01-19_112552

»crosslinked«

Tagged with:
 

One Response to From HEX to DEC and back

  1. From HEX to DEC and back « H9Newser’s Blog says:

    […] 20, 2009 From HEX to DEC and back: […]

Leave a Reply