-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for 128-bit integers to BitConverter #91299
Add support for 128-bit integers to BitConverter #91299
Conversation
Tagging subscribers to this area: @dotnet/area-system-numerics Issue Details128-bit integers were introduced with .NET 7 (#69204), but support for it has yet to be added to BitConverter. This pull request adds methods for Int128 and UInt128, and corrects at typo in an existing XML comment for a ulong method. Fixes #80337
|
This comment was marked as outdated.
This comment was marked as outdated.
/// </summary> | ||
/// <param name="value">The number to convert.</param> | ||
/// <returns>An array of bytes with length 16.</returns> | ||
public static byte[] GetBytes(Int128 value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public static byte[] GetBytes(Int128 value) | |
public static unsafe byte[] GetBytes(Int128 value) |
To fix the compiler error.
Or as alternative you could use
byte[] bytes = new byte[Unsafe.SizeOf<Int128>()];
The former is prefered, as it's less work the JIT.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also use the Int128.Size
internal constant, which exists since its a fixed sized type that will never change.
The API proposal has not been approved yet (though it will likely be), and this PR can't be merged. To expose a public API, you need also to update the reference assembly at |
Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it. |
128-bit integers were introduced with .NET 7 (#69204), but support for it has yet to be added to BitConverter.
This pull request adds methods for Int128 and UInt128, and corrects at typo in an existing XML comment for a ulong method.
Fixes #80337