powershellhexlarge-datalargenumber

Powershell large hex range


I am trying to make a range of hex from a000000000-afffffffff, but the values are too large for Int32. Getting error Cannot convert value "687194767360" to type "System.Int32". Error: "Value was either too large or too small for an Int32."

Here is the code (0xa000000000..0xafffffffff|% ToString X10).ToLower()


Solution

  • The endpoints of .., the range operator, must fit into [int] values, which your numbers exceed.

    Similarly, the [Linq.Enumerable]::Range() method unfortunately also only accepts [int] endpoints.

    However, you can implement a (custom) streaming solution, where PowerShell creates and emits each formatted number (string) to the pipeline one by one:

    $num = 0xa000000000
    while ($num -le 0xafffffffff) { ($num++).ToString('x10') }
    

    Note: