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()
The endpoints of ..
, the range operator, must fit into [int]
values, which your numbers exceed.
0xa000000000..0xafffffffff| % ToString X10
pipeline command in memory in full, by enclosing it in (...)
and calling method .ToString()
on it, the collected outputs would have to fit into an array, and the count of elements in your range exceed the max. capacity of a .NET array too.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:
While this works, it will be slow.
You won't be able to capture the result as a whole in a collection in memory.