Skip to content

BigInteger.TryParse incorrectly parses "80000000" from hex as -4294967295 #54251

@rjmholt

Description

@rjmholt

Description

From PowerShell/PowerShell#15587.

Possibly related to #50385?

However, in this case this behaviour represents a regression from .NET 6 preview 5.

Repro:

using System;
using System.Diagnostics;
using System.Globalization;
using System.Numerics;
using System.Runtime.InteropServices;

namespace repro
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine($".NET: '{RuntimeInformation.FrameworkDescription}'");

            string numStr = args.Length > 0
                ? args[0]
                : "80000000";

            BigInteger.TryParse(numStr, NumberStyles.AllowHexSpecifier, NumberFormatInfo.InvariantInfo, out BigInteger bi);

            Console.WriteLine($"Expected: '{numStr}'");
            Console.WriteLine($"Actual: '{bi.ToString("X")}'");

            Debug.Assert(bi.ToString("X") == numStr);
        }
    }
}

Configuration

x64 Windows PC:

OS Name:                   Microsoft Windows 10 Pro
OS Version:                10.0.19043 N/A Build 19043
> dotnet version
6.0.100-preview.5.21302.13

Regression?

This previously worked in .NET 6 preview 4.

Other information

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions