diff --git a/docs/standard/base-types/parsing-numeric.md b/docs/standard/base-types/parsing-numeric.md index 4e23aa3484e93..0ac4ccf493a98 100644 --- a/docs/standard/base-types/parsing-numeric.md +++ b/docs/standard/base-types/parsing-numeric.md @@ -61,6 +61,7 @@ All numeric types have two static parsing methods, `Parse` and `TryParse`, that ||The group separator is permitted. The group separator character is determined by the or property.| ||The currency symbol is permitted. The currency symbol is defined by the property.| ||The string to be parsed is interpreted as a hexadecimal number. It can include the hexadecimal digits 0-9, A-F, and a-f. This flag can be used only to parse integer values.| +||The string to be parsed is interpreted as a binary number. It can include the binary digits 0 and 1. This flag can be used only to parse integer values.| In addition, the enumeration provides the following composite styles, which include multiple flags. @@ -72,6 +73,13 @@ All numeric types have two static parsing methods, `Parse` and `TryParse`, that ||Includes all styles except and .| ||Includes all styles except .| ||Includes the , , and styles.| +||Includes the , , and styles.| + +## Parsing binary and hexadecimal BigIntegers + +When parsing with the or flags, the input string is interpreted as a hexadecimal/binary number of exactly the length the string has. +For instance, parsing `"11"` as a binary BigInteger yields `-1`, because that is the interpretation of `11` as a signed two's complement value with exactly 2 digits. +If you want a positive result, add a leading `0`, such as `"011"` which is parsed as `3`. ## Parsing and Unicode Digits diff --git a/docs/standard/base-types/standard-numeric-format-strings.md b/docs/standard/base-types/standard-numeric-format-strings.md index 2d88f76072324..e4669d0e6acce 100644 --- a/docs/standard/base-types/standard-numeric-format-strings.md +++ b/docs/standard/base-types/standard-numeric-format-strings.md @@ -98,6 +98,8 @@ The binary ("B") format specifier converts a number to a string of binary digits The precision specifier indicates the minimum number of digits desired in the resulting string. If required, the number is padded with zeros to its left to produce the number of digits given by the precision specifier. +For , positive values always have a leading zero to distinguish them from negative values. This ensures the output round-trips to the original value when parsed. For instance, the number `3` converted with the format specifier `"B2"` is `"011"`. That's because the binary number `"11"` represents the negative value `-1`, as it is interpreted as a number with exactly `2` bits due to the `"B2"` format. + The result string is not affected by the formatting information of the current object. @@ -309,6 +311,9 @@ The hexadecimal ("X") format specifier converts a number to a string of hexadeci The precision specifier indicates the minimum number of digits desired in the resulting string. If required, the number is padded with zeros to its left to produce the number of digits given by the precision specifier. +For , positive values always have a leading zero to distinguish them from negative values. This ensures the output round-trips to the original value when parsed. +For instance, the number `F` converted with the format specifier `"X1"` is `0F` because the hexadecimal number `F` represents the negative value `-1`. + The result string is not affected by the formatting information of the current object. The following example formats values with the hexadecimal format specifier.