Skip to content

BigInteger incorrectly parses large integer hex string #50385

@alexhelms

Description

@alexhelms

Description

The following expression results in the wrong parsed value:

string s = BigInteger.Parse("FFFFFFFFFFFFFFFF01", NumberStyles.HexNumber, null).ToString("X")
Debug.Assert(s == "F01");

I would expect the string to be the same as the input -- FFFFFFFFFFFFFFFF01. Further, any number of Fs results in the same F01 result.

Trying another huge number results in the correct parsing:

string s = BigInteger.Parse("abcdefabcdefabcdefabcdefabcdef", NumberStyles.HexNumber, null).ToString("X")
Debug.Assert(s == "ABCDEFABCDEFABCDEFABCDEFABCDEF");

Configuration

.NET SDK (reflecting any global.json):
 Version:   5.0.201
 Commit:    a09bd5c86c

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.18362
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\5.0.201\

Host (useful for support):
  Version: 5.0.4
  Commit:  f27d337295

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions