-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathConvert-Int64ToUint64.ps1
62 lines (55 loc) · 1.88 KB
/
Convert-Int64ToUint64.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
62
function Convert-Int64ToUint64 {
<#
.SYNOPSIS
Converts int64 values to uint64 values
.DESCRIPTION
Converts int64 values to uint64 values. Useful for handling 32 bitmasks returned from some functions like Get-Acl
.PARAMETER Number
An array of int64 values
.PARAMETER IncludeInput
Switch to include the input in the output
.EXAMPLE
Convert-int64ToUint64 -Number -1610612736,-1,0x800000000000005b -IncludeInput
int64 Uint64
----- ------
-1610612736 18446744072098938880
-1 18446744073709551615
-9223372036854775717 9223372036854775899
.EXAMPLE
Convert-int64ToUint64 -Number -1610612736
2684354560
#>
#region Parameter
[CmdletBinding(ConfirmImpact = 'None', HelpURI='https://undernewmanagement.info/2021/06/pick-up-the-bow/')]
Param(
[parameter(Mandatory, HelpMessage = 'Enter hex color val RGB in form #RRGGBB', ValueFromPipeline)]
[int64[]] $Number,
[switch] $IncludeInput
)
#endregion Parameter
begin {
Write-Verbose -Message "Starting [$($MyInvocation.Mycommand)]"
}
process {
foreach ($curNumber in $Number) {
$HexString = '{0:x}' -f $curNumber
[int64] $power = 0
[uint64] $ReturnVal = 0
for ($i = ($Hexstring.length - 1); $i -ge 0; $i--) {
$ReturnVal += ([int64] "0x$($Hexstring.Substring($i,1))" * [bigint]::Pow(16, $power))
$power++
}
if ($IncludeInput) {
New-Object -TypeName psobject -Property ([ordered] @{
int64 = $curNumber
Uint64 = $ReturnVal
})
} else {
Write-Output -InputObject $ReturnVal
}
}
}
end {
Write-Verbose -Message "Ending [$($MyInvocation.Mycommand)]"
}
}