-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathConvert-Int32ToUint32.ps1
61 lines (54 loc) · 1.7 KB
/
Convert-Int32ToUint32.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
function Convert-Int32ToUint32 {
<#
.SYNOPSIS
Converts int32 values to uint32 values
.DESCRIPTION
Converts int32 values to uint32 values. Useful for handling 32 bitmasks returned from some functions like Get-Acl
.PARAMETER Number
An array of int32 values
.PARAMETER IncludeInput
Switch to include the input in the output
.EXAMPLE
Convert-Int32ToUint32 -Number -1610612736,-1 -IncludeInput
Int32 Uint32
----- ------
-1610612736 2684354560
-1 4294967295
.EXAMPLE
Convert-Int32ToUint32 -Number -1610612736
2684354560
#>
#region Parameter
[CmdletBinding(ConfirmImpact = 'None')]
Param(
[parameter(Mandatory, HelpMessage = 'Enter hex color val RGB in form #RRGGBB', ValueFromPipeline)]
[int32[]] $Number,
[switch] $IncludeInput
)
#endregion Parameter
begin {
Write-Verbose -Message "Starting [$($MyInvocation.Mycommand)]"
}
process {
foreach ($curNumber in $Number) {
$HexString = '{0:x}' -f $curNumber
[int] $power = 0
[uint32] $ReturnVal = 0
for ($i = ($Hexstring.length - 1); $i -ge 0; $i--) {
$ReturnVal += ([int] "0x$($Hexstring.Substring($i,1))" * [bigint]::Pow(16, $power))
$power++
}
if ($IncludeInput) {
New-Object -TypeName psobject -Property ([ordered] @{
Int32 = $curNumber
Uint32 = $ReturnVal
})
} else {
Write-Output -InputObject $ReturnVal
}
}
}
end {
Write-Verbose -Message "Ending [$($MyInvocation.Mycommand)]"
}
}