Skip to content
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

Conversation

mikaeldui
Copy link

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

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Aug 29, 2023
@ghost
Copy link

ghost commented Aug 29, 2023

Tagging subscribers to this area: @dotnet/area-system-numerics
See info in area-owners.md if you want to be subscribed.

Issue Details

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

Author: mikaeldui
Assignees: -
Labels:

area-System.Numerics

Milestone: -

@mikaeldui

This comment was marked as outdated.

@mikaeldui mikaeldui marked this pull request as draft August 30, 2023 00:35
/// </summary>
/// <param name="value">The number to convert.</param>
/// <returns>An array of bytes with length 16.</returns>
public static byte[] GetBytes(Int128 value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.

Copy link
Member

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.

@huoyaoyuan
Copy link
Member

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 src\libraries\System.Runtime\ref. See https://github.com/dotnet/runtime/blob/main/docs/coding-guidelines/updating-ref-source.md

@ghost ghost closed this Oct 7, 2023
@ghost
Copy link

ghost commented Oct 7, 2023

Draft Pull Request was automatically closed for 30 days of inactivity. Please let us know if you'd like to reopen it.

@ghost ghost locked as resolved and limited conversation to collaborators Nov 6, 2023
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Numerics community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[API Proposal]: Add Int128 and UInt128 BitConverter.GetBytes support
4 participants