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«

No related posts.

  One Response to “From HEX to DEC and back”

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

 Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">

   
© 2012 PeetersOnline Suffusion theme by Sayontan Sinha