Skip to content

Update BitConverter.xml #9809

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

Merged
merged 1 commit into from
Apr 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions xml/System/BitConverter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,19 @@
## Remarks
The <xref:System.BitConverter> class helps manipulate value types in their fundamental form, as a series of bytes. A byte is defined as an 8-bit unsigned integer. The <xref:System.BitConverter> class includes static methods to convert each of the primitive types to and from an array of bytes, as the following table illustrates.

|Type|To byte conversion|From byte conversion|
|----------|------------------------|--------------------------|
|<xref:System.Boolean>|<xref:System.BitConverter.GetBytes%28System.Boolean%29>|<xref:System.BitConverter.ToBoolean%2A>|
|<xref:System.Char>|<xref:System.BitConverter.GetBytes%28System.Char%29>|<xref:System.BitConverter.ToChar%2A>|
|<xref:System.Double>|<xref:System.BitConverter.GetBytes%28System.Double%29><br /><br /> -or-<br /><br /> <xref:System.BitConverter.DoubleToInt64Bits%28System.Double%29>|<xref:System.BitConverter.ToDouble%2A><br /><br /> -or-<br /><br /> <xref:System.BitConverter.Int64BitsToDouble%2A>|
|<xref:System.Int16>|<xref:System.BitConverter.GetBytes%28System.Int16%29>|<xref:System.BitConverter.ToInt16%2A>|
|<xref:System.Int32>|<xref:System.BitConverter.GetBytes%28System.Int32%29>|<xref:System.BitConverter.ToInt32%2A>|
|<xref:System.Int64>|<xref:System.BitConverter.GetBytes%28System.Int64%29>|<xref:System.BitConverter.ToInt64%2A>|
|<xref:System.Single>|<xref:System.BitConverter.GetBytes%28System.Single%29>|<xref:System.BitConverter.ToSingle%2A>|
|<xref:System.UInt16>|<xref:System.BitConverter.GetBytes%28System.UInt16%29>|<xref:System.BitConverter.ToUInt16%2A>|
|<xref:System.UInt32>|<xref:System.BitConverter.GetBytes%28System.UInt32%29>|<xref:System.BitConverter.ToUInt32%2A>|
|<xref:System.UInt64>|<xref:System.BitConverter.GetBytes%28System.UInt64%29>|<xref:System.BitConverter.ToUInt64%2A>|
| Type | To byte conversion | From byte conversion |
|-----------------------|--------------------------------------------------------|-----------------------------------------|
| <xref:System.Boolean> | <xref:System.BitConverter.GetBytes%28System.Boolean%29>| <xref:System.BitConverter.ToBoolean%2A> |
| <xref:System.Char> | <xref:System.BitConverter.GetBytes%28System.Char%29> | <xref:System.BitConverter.ToChar%2A> |
| <xref:System.Double> | <xref:System.BitConverter.GetBytes%28System.Double%29><br />-or-<br /><xref:System.BitConverter.DoubleToInt64Bits%28System.Double%29><br />-or-<br /><xref:System.BitConverter.DoubleToUInt64Bits%28System.Double%29> | <xref:System.BitConverter.ToDouble%2A><br />-or-<br /><xref:System.BitConverter.Int64BitsToDouble%2A><br />-or-<br /><xref:System.BitConverter.UInt64BitsToDouble%2A> |
| <xref:System.Half> | <xref:System.BitConverter.GetBytes%28System.Half%29><br />-or-<br /><xref:System.BitConverter.HalfToInt16Bits%28System.Half%29><br />-or-<br /><xref:System.BitConverter.HalfToUInt16Bits%28System.Half%29> | <xref:System.BitConverter.ToHalf%2A><br />-or-<br /><xref:System.BitConverter.Int16BitsToHalf%2A><br />-or-<br /><xref:System.BitConverter.UInt16BitsToHalf%2A> |
| <xref:System.Int16> | <xref:System.BitConverter.GetBytes%28System.Int16%29> | <xref:System.BitConverter.ToInt16%2A> |
| <xref:System.Int32> | <xref:System.BitConverter.GetBytes%28System.Int32%29> | <xref:System.BitConverter.ToInt32%2A> |
| <xref:System.Int64> | <xref:System.BitConverter.GetBytes%28System.Int64%29> | <xref:System.BitConverter.ToInt64%2A> |
| <xref:System.Single> | <xref:System.BitConverter.GetBytes%28System.Single%29><br />-or-<br /><xref:System.BitConverter.SingleToInt32Bits%28System.Single%29><br />-or-<br /><xref:System.BitConverter.SingleToUInt32Bits%28System.Single%29> | <xref:System.BitConverter.ToSingle%2A><br />-or-<br /><xref:System.BitConverter.Int32BitsToSingle%2A><br />-or-<br /><xref:System.BitConverter.UInt32BitsToSingle%2A> |
| <xref:System.UInt16> | <xref:System.BitConverter.GetBytes%28System.UInt16%29> | <xref:System.BitConverter.ToUInt16%2A> |
| <xref:System.UInt32> | <xref:System.BitConverter.GetBytes%28System.UInt32%29> | <xref:System.BitConverter.ToUInt32%2A> |
| <xref:System.UInt64> | <xref:System.BitConverter.GetBytes%28System.UInt64%29> | <xref:System.BitConverter.ToUInt64%2A> |

If you use <xref:System.BitConverter> methods to round-trip data, make sure that the <xref:System.BitConverter.GetBytes%2A> overload and the `To`*Type* method specify the same type. As the following example illustrates, restoring an array that represents a signed integer by calling the <xref:System.BitConverter.ToUInt32%2A> method can result in a value that is different from the original. For more information, see [Working with Signed Non-Decimal and Bitwise Values](/archive/blogs/bclteam/working-with-signed-non-decimal-and-bitwise-values-ron-petrusha).

Expand Down
Loading