Skip to content

BigInteger.Parse creates invalid instances from hex strings #74758

@adetunji-david

Description

@adetunji-david

Description

By design, the following expression creates an instance of BigInteger with the value of -2
var x = BigInteger.Parse("FFFFFFFFE", NumberStyles.HexNumber);
However, x is not equal to another instance with a value of -2.

Reproduction Steps

var x = BigInteger.Parse("FFFFFFFFE", NumberStyles.HexNumber);
var minusTwo = new BigInteger(-2);
Console.WriteLine(x);
Console.WriteLine(x == minusTwo);
Console.WriteLine(x == -2);

Expected behavior

Output is
-2
True
True

Actual behavior

Output is
-2
True
False

Regression?

No response

Known Workarounds

No response

Configuration

.Net version: 6.0.300
Operating System: Microsoft Windows 10 Pro
Architecture: x64

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions