Skip to content

Commit c446dfe

Browse files
authored
Merge pull request #4333 from MicrosoftDocs/main638060348175737631sync_temp
Repo sync for protected CLA branch
2 parents 49ec212 + 420b0b9 commit c446dfe

File tree

2 files changed

+90
-90
lines changed

2 files changed

+90
-90
lines changed

docs/c-language/conversions-from-signed-integral-types.md

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
---
22
description: "Learn more about: Conversions from signed integral types"
33
title: "Conversions from signed integral types"
4-
ms.date: "10/02/2019"
4+
ms.date: 12/06/2022
55
helpviewer_keywords: ["integral conversions, from signed", "integers, converting", "conversions [C++], integral", "data type conversion [C++], signed and unsigned integers", "type conversion [C++], signed and unsigned integers"]
66
ms.assetid: 5eea32f8-8b14-413d-acac-c063b3d118d7
77
---
88
# Conversions from signed integral types
99

10-
When a signed integer is converted to an integer or a floating-point type, if the original value is representable in the result type, the value is unchanged.
10+
When a signed integer is converted to an integer or a floating-point type, the value is unchanged if it's representable in the result type.
1111

1212
When a signed integer is converted to an integer of greater size, the value is sign-extended. When converted to an integer of smaller size, the high-order bits are truncated. The result is interpreted using the result type, as shown in this example:
1313

@@ -19,7 +19,7 @@ u = i;
1919
printf_s( "%hu\n", u ); // Prints 65533
2020
```
2121
22-
When converting a signed integer to a floating-point type, if the original value isn't representable exactly in the result type, the result is the next higher or lower representable value.
22+
When the compiler converts a signed integer to a floating-point type, if the original value isn't representable exactly in the result type, the result is the next higher or lower representable value.
2323
2424
For information about the sizes of integral and floating-point types, see [Storage of basic types](../c-language/storage-of-basic-types.md).
2525
@@ -33,48 +33,48 @@ In the Microsoft compiler, **`int`** and **`long`** are distinct but equivalent
3333
3434
## Table of conversions from signed integral types
3535
36-
|From|To|Method|
37-
|----------|--------|------------|
38-
|**`char`**<sup>1</sup>|**`short`**|Sign-extend|
39-
|**`char`**|**`long`**|Sign-extend|
40-
|**`char`**|**`long long`**|Sign-extend|
41-
|**`char`**|**`unsigned char`**|Preserve pattern; high-order bit loses function as sign bit|
42-
|**`char`**|**`unsigned short`**|Sign-extend to **`short`**; convert **`short`** to **`unsigned short`**|
43-
|**`char`**|**`unsigned long`**|Sign-extend to **`long`**; convert **`long`** to **`unsigned long`**|
44-
|**`char`**|**`unsigned long long`**|Sign-extend to **`long long`**; convert **`long long`** to **`unsigned long long`**|
45-
|**`char`**|**`float`**|Sign-extend to **`long`**; convert **`long`** to **`float`**|
46-
|**`char`**|**`double`**|Sign-extend to **`long`**; convert **`long`** to **`double`**|
47-
|**`char`**|**`long double`**|Sign-extend to **`long`**; convert **`long`** to **`double`**|
48-
|**`short`**|**`char`**|Preserve low-order byte|
49-
|**`short`**|**`long`**|Sign-extend|
50-
|**`short`**|**`long long`**|Sign-extend|
51-
|**`short`**|**`unsigned char`**|Preserve low-order byte|
52-
|**`short`**|**`unsigned short`**|Preserve bit pattern; high-order bit loses function as sign bit|
53-
|**`short`**|**`unsigned long`**|Sign-extend to **`long`**; convert **`long`** to **`unsigned long`**|
54-
|**`short`**|**`unsigned long long`**|Sign-extend to **`long long`**; convert **`long long`** to **`unsigned long long`**|
55-
|**`short`**|**`float`**|Sign-extend to **`long`**; convert **`long`** to **`float`**|
56-
|**`short`**|**`double`**|Sign-extend to **`long`**; convert **`long`** to **`double`**|
57-
|**`short`**|**`long double`**|Sign-extend to **`long`**; convert **`long`** to **`double`**|
58-
|**`long`**|**`char`**|Preserve low-order byte|
59-
|**`long`**|**`short`**|Preserve low-order word|
60-
|**`long`**|**`long long`**|Sign-extend|
61-
|**`long`**|**`unsigned char`**|Preserve low-order byte|
62-
|**`long`**|**`unsigned short`**|Preserve low-order word|
63-
|**`long`**|**`unsigned long`**|Preserve bit pattern; high-order bit loses function as sign bit|
64-
|**`long`**|**`unsigned long long`**|Sign-extend to **`long long`**; convert **`long long`** to **`unsigned long long`**|
65-
|**`long`**|**`float`**|Represent as **`float`**. If **`long`** can't be represented exactly, some precision is lost.|
66-
|**`long`**|**`double`**|Represent as **`double`**. If **`long`** can't be represented exactly as a **`double`**, some precision is lost.|
67-
|**`long`**|**`long double`**|Represent as **`double`**. If **`long`** can't be represented exactly as a **`double`**, some precision is lost.|
68-
|**`long long`**|**`char`**|Preserve low-order byte|
69-
|**`long long`**|**`short`**|Preserve low-order word|
70-
|**`long long`**|**`long`**|Preserve low-order dword|
71-
|**`long long`**|**`unsigned char`**|Preserve low-order byte|
72-
|**`long long`**|**`unsigned short`**|Preserve low-order word|
73-
|**`long long`**|**`unsigned long`**|Preserve low-order dword|
74-
|**`long long`**|**`unsigned long long`**|Preserve bit pattern; high-order bit loses function as sign bit|
75-
|**`long long`**|**`float`**|Represent as **`float`**. If **`long long`** can't be represented exactly, some precision is lost.|
76-
|**`long long`**|**`double`**|Represent as **`double`**. If **`long long`** can't be represented exactly as a **`double`**, some precision is lost.|
77-
|**`long long`**|**`long double`**|Represent as **`double`**. If **`long long`** can't be represented exactly as a **`double`**, some precision is lost.|
36+
| From | To | Method |
37+
|---|---|---|
38+
| **`char`**<sup>1</sup> | **`short`** | Sign-extend |
39+
| **`char`** | **`long`** | Sign-extend |
40+
| **`char`** | **`long long`** | Sign-extend |
41+
| **`char`** | **`unsigned char`** | Preserve pattern; high-order bit loses function as sign bit |
42+
| **`char`** | **`unsigned short`** | Sign-extend to **`short`**; convert **`short`** to **`unsigned short`** |
43+
| **`char`** | **`unsigned long`** | Sign-extend to **`long`**; convert **`long`** to **`unsigned long`** |
44+
| **`char`** | **`unsigned long long`** | Sign-extend to **`long long`**; convert **`long long`** to **`unsigned long long`** |
45+
| **`char`** | **`float`** | Represent exactly as **`float`** |
46+
| **`char`** | **`double`** | Represent exactly as **`double`** |
47+
| **`char`** | **`long double`** | Represent exactly as **`long double`** |
48+
| **`short`** | **`char`** | Preserve low-order byte |
49+
| **`short`** | **`long`** | Sign-extend |
50+
| **`short`** | **`long long`** | Sign-extend |
51+
| **`short`** | **`unsigned char`** | Preserve low-order byte |
52+
| **`short`** | **`unsigned short`** | Preserve bit pattern; high-order bit loses function as sign bit |
53+
| **`short`** | **`unsigned long`** | Sign-extend to **`long`**; convert **`long`** to **`unsigned long`** |
54+
| **`short`** | **`unsigned long long`** | Sign-extend to **`long long`**; convert **`long long`** to **`unsigned long long`** |
55+
| **`short`** | **`float`** | Represent exactly as **`float`** |
56+
| **`short`** | **`double`** | Represent exactly as **`double`** |
57+
| **`short`** | **`long double`** | Represent exactly as **`long double`** |
58+
| **`long`** | **`char`** | Preserve low-order byte |
59+
| **`long`** | **`short`** | Preserve low-order word |
60+
| **`long`** | **`long long`** | Sign-extend |
61+
| **`long`** | **`unsigned char`** | Preserve low-order byte |
62+
| **`long`** | **`unsigned short`** | Preserve low-order word |
63+
| **`long`** | **`unsigned long`** | Preserve bit pattern; high-order bit loses function as sign bit |
64+
| **`long`** | **`unsigned long long`** | Sign-extend to **`long long`**; convert **`long long`** to **`unsigned long long`** |
65+
| **`long`** | **`float`** | Represent as **`float`**. If **`long`** can't be represented exactly, some precision is lost. |
66+
| **`long`** | **`double`** | Represent exactly as **`double`** |
67+
| **`long`** | **`long double`** | Represent exactly as **`long double`** |
68+
| **`long long`** | **`char`** | Preserve low-order byte |
69+
| **`long long`** | **`short`** | Preserve low-order word |
70+
| **`long long`** | **`long`** | Preserve low-order dword |
71+
| **`long long`** | **`unsigned char`** | Preserve low-order byte |
72+
| **`long long`** | **`unsigned short`** | Preserve low-order word |
73+
| **`long long`** | **`unsigned long`** | Preserve low-order dword |
74+
| **`long long`** | **`unsigned long long`** | Preserve bit pattern; high-order bit loses function as sign bit |
75+
| **`long long`** | **`float`** | Represent as **`float`**. If **`long long`** can't be represented exactly, some precision is lost. |
76+
| **`long long`** | **`double`** | Represent as **`double`**. If **`long long`** can't be represented exactly as a **`double`**, some precision is lost. |
77+
| **`long long`** | **`long double`** | Represent as **`double`**. If **`long long`** can't be represented exactly as a **`double`**, some precision is lost. |
7878
7979
<sup>1</sup> All **`char`** entries assume that the **`char`** type is signed by default.
8080

docs/c-language/conversions-from-unsigned-integral-types.md

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
---
22
description: "Learn more about: Conversions from unsigned integral types"
33
title: "Conversions from unsigned integral types"
4-
ms.date: "10/02/2019"
4+
ms.date: 12/06/2022
55
helpviewer_keywords: ["integers, converting", "type casts, involving integers", "data type conversion [C++], signed and unsigned integers", "type conversion [C++], signed and unsigned integers", "integral conversions, from unsigned"]
66
ms.assetid: 60fb7e10-bff9-4a13-8a48-e19f25a36a02
77
---
88
# Conversions from unsigned integral types
99

1010
When an unsigned integer is converted to an integer or floating-point type, if the original value is representable in the result type the value is unchanged.
1111

12-
When converting an unsigned integer to an integer of greater size, the value is zero-extended. When converting to an integer of smaller size, the high-order bits are truncated. The result is interpreted using the result type, as shown in this example.
12+
When the compiler converts an unsigned integer to an integer of greater size, the value is zero-extended. When converted to an integer of smaller size, the high-order bits are truncated. The result is interpreted using the result type, as shown in this example:
1313

1414
```C
1515
unsigned k = 65533;
@@ -19,7 +19,7 @@ j = k;
1919
printf_s( "%hd\n", j ); // Prints -3
2020
```
2121
22-
When converting an unsigned integer to a floating-point type, if the original value can't be represented exactly in the result type, the result is the next higher or lower representable value.
22+
When the compiler converts an unsigned integer to a floating-point type, if the original value isn't representable exactly in the result type, the result is the next higher or lower representable value.
2323
2424
See [Storage of basic types](../c-language/storage-of-basic-types.md) for information about the sizes of integral and floating-point types.
2525
@@ -33,48 +33,48 @@ The following table summarizes conversions from unsigned integral types.
3333
3434
## Table of conversions from unsigned integral types
3535
36-
|From|To|Method|
37-
|----------|--------|------------|
38-
|**`unsigned char`**|**`char`**|Preserve bit pattern; high-order bit becomes sign bit|
39-
|**`unsigned char`**|**`short`**|Zero-extend|
40-
|**`unsigned char`**|**`long`**|Zero-extend|
41-
|**`unsigned char`**|**`long long`**|Zero-extend|
42-
|**`unsigned char`**|**`unsigned short`**|Zero-extend|
43-
|**`unsigned char`**|**`unsigned long`**|Zero-extend|
44-
|**`unsigned char`**|**`unsigned long long`**|Zero-extend|
45-
|**`unsigned char`**|**`float`**|Convert to **`long`**; convert **`long`** to **`float`**|
46-
|**`unsigned char`**|**`double`**|Convert to **`long`**; convert **`long`** to **`double`**|
47-
|**`unsigned char`**|**`long double`**|Convert to **`long`**; convert **`long`** to **`double`**|
48-
|**`unsigned short`**|**`char`**|Preserve low-order byte|
49-
|**`unsigned short`**|**`short`**|Preserve bit pattern; high-order bit becomes sign bit|
50-
|**`unsigned short`**|**`long`**|Zero-extend|
51-
|**`unsigned short`**|**`long long`**|Zero-extend|
52-
|**`unsigned short`**|**`unsigned char`**|Preserve low-order byte|
53-
|**`unsigned short`**|**`unsigned long`**|Zero-extend|
54-
|**`unsigned short`**|**`unsigned long long`**|Zero-extend|
55-
|**`unsigned short`**|**`float`**|Convert to **`long`**; convert **`long`** to **`float`**|
56-
|**`unsigned short`**|**`double`**|Convert to **`long`**; convert **`long`** to **`double`**|
57-
|**`unsigned short`**|**`long double`**|Convert to **`long`**; convert **`long`** to **`double`**|
58-
|**`unsigned long`**|**`char`**|Preserve low-order byte|
59-
|**`unsigned long`**|**`short`**|Preserve low-order word|
60-
|**`unsigned long`**|**`long`**|Preserve bit pattern; high-order bit becomes sign bit|
61-
|**`unsigned long`**|**`long long`**|Zero-extend|
62-
|**`unsigned long`**|**`unsigned char`**|Preserve low-order byte|
63-
|**`unsigned long`**|**`unsigned short`**|Preserve low-order word|
64-
|**`unsigned long`**|**`unsigned long long`**|Zero-extend|
65-
|**`unsigned long`**|**`float`**|Convert to **`long`**; convert **`long`** to **`float`**|
66-
|**`unsigned long`**|**`double`**|Convert directly to **`double`**|
67-
|**`unsigned long`**|**`long double`**|Convert to **`long`**; convert **`long`** to **`double`**|
68-
|**`unsigned long long`**|**`char`**|Preserve low-order byte|
69-
|**`unsigned long long`**|**`short`**|Preserve low-order word|
70-
|**`unsigned long long`**|**`long`**|Preserve low-order dword|
71-
|**`unsigned long long`**|**`long long`**|Preserve bit pattern; high-order bit becomes sign bit|
72-
|**`unsigned long long`**|**`unsigned char`**|Preserve low-order byte|
73-
|**`unsigned long long`**|**`unsigned short`**|Preserve low-order word|
74-
|**`unsigned long long`**|**`unsigned long`**|Preserve low-order dword|
75-
|**`unsigned long long`**|**`float`**|Convert to **`long`**; convert **`long`** to **`float`**|
76-
|**`unsigned long long`**|**`double`**|Convert directly to **`double`**|
77-
|**`unsigned long long`**|**`long double`**|Convert to **`long`**; convert **`long`** to **`double`**|
36+
| From | To | Method |
37+
|---|---|---|
38+
| **`unsigned char`** | **`char`** | Preserve bit pattern; high-order bit becomes sign bit |
39+
| **`unsigned char`** | **`short`** | Zero-extend |
40+
| **`unsigned char`** | **`long`** | Zero-extend |
41+
| **`unsigned char`** | **`long long`** | Zero-extend |
42+
| **`unsigned char`** | **`unsigned short`** | Zero-extend |
43+
| **`unsigned char`** | **`unsigned long`** | Zero-extend |
44+
| **`unsigned char`** | **`unsigned long long`** | Zero-extend |
45+
| **`unsigned char`** | **`float`** | Convert exactly to **`float`** |
46+
| **`unsigned char`** | **`double`** | Convert exactly to **`double`** |
47+
| **`unsigned char`** | **`long double`** | Convert exactly to **`long double`** |
48+
| **`unsigned short`** | **`char`** | Preserve low-order byte |
49+
| **`unsigned short`** | **`short`** | Preserve bit pattern; high-order bit becomes sign bit |
50+
| **`unsigned short`** | **`long`** | Zero-extend |
51+
| **`unsigned short`** | **`long long`** | Zero-extend |
52+
| **`unsigned short`** | **`unsigned char`** | Preserve low-order byte |
53+
| **`unsigned short`** | **`unsigned long`** | Zero-extend |
54+
| **`unsigned short`** | **`unsigned long long`** | Zero-extend |
55+
| **`unsigned short`** | **`float`** | Convert exactly to **`float`** |
56+
| **`unsigned short`** | **`double`** | Convert exactly to **`double`** |
57+
| **`unsigned short`** | **`long double`** | Convert exactly to **`long double`** |
58+
| **`unsigned long`** | **`char`** | Preserve low-order byte |
59+
| **`unsigned long`** | **`short`** | Preserve low-order word |
60+
| **`unsigned long`** | **`long`** | Preserve bit pattern; high-order bit becomes sign bit |
61+
| **`unsigned long`** | **`long long`** | Zero-extend |
62+
| **`unsigned long`** | **`unsigned char`** | Preserve low-order byte |
63+
| **`unsigned long`** | **`unsigned short`** | Preserve low-order word |
64+
| **`unsigned long`** | **`unsigned long long`** | Zero-extend |
65+
| **`unsigned long`** | **`float`** | Convert to nearest representable **`float`** |
66+
| **`unsigned long`** | **`double`** | Convert exactly to **`double`** |
67+
| **`unsigned long`** | **`long double`** | Convert exactly to **`long double`** |
68+
| **`unsigned long long`** | **`char`** | Preserve low-order byte |
69+
| **`unsigned long long`** | **`short`** | Preserve low-order word |
70+
| **`unsigned long long`** | **`long`** | Preserve low-order dword |
71+
| **`unsigned long long`** | **`long long`** | Preserve bit pattern; high-order bit becomes sign bit |
72+
| **`unsigned long long`** | **`unsigned char`** | Preserve low-order byte |
73+
| **`unsigned long long`** | **`unsigned short`** | Preserve low-order word |
74+
| **`unsigned long long`** | **`unsigned long`** | Preserve low-order dword |
75+
| **`unsigned long long`** | **`float`** | Convert to nearest representable **`float`** |
76+
| **`unsigned long long`** | **`double`** | Convert to nearest representable **`double`** |
77+
| **`unsigned long long`** | **`long double`** | Convert to nearest representable **`long double`** |
7878
7979
## See also
8080

0 commit comments

Comments
 (0)