You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/c-language/conversions-from-signed-integral-types.md
+45-45Lines changed: 45 additions & 45 deletions
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,13 @@
1
1
---
2
2
description: "Learn more about: Conversions from signed integral types"
3
3
title: "Conversions from signed integral types"
4
-
ms.date: "10/02/2019"
4
+
ms.date: 12/06/2022
5
5
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"]
6
6
ms.assetid: 5eea32f8-8b14-413d-acac-c063b3d118d7
7
7
---
8
8
# Conversions from signed integral types
9
9
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.
11
11
12
12
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:
13
13
@@ -19,7 +19,7 @@ u = i;
19
19
printf_s( "%hu\n", u ); // Prints 65533
20
20
```
21
21
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.
23
23
24
24
For information about the sizes of integral and floating-point types, see [Storage of basic types](../c-language/storage-of-basic-types.md).
25
25
@@ -33,48 +33,48 @@ In the Microsoft compiler, **`int`** and **`long`** are distinct but equivalent
33
33
34
34
## Table of conversions from signed integral types
35
35
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`**|
|**`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.|
|**`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.|
78
78
79
79
<sup>1</sup> All **`char`** entries assume that the **`char`** type is signed by default.
Copy file name to clipboardExpand all lines: docs/c-language/conversions-from-unsigned-integral-types.md
+45-45Lines changed: 45 additions & 45 deletions
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,15 @@
1
1
---
2
2
description: "Learn more about: Conversions from unsigned integral types"
3
3
title: "Conversions from unsigned integral types"
4
-
ms.date: "10/02/2019"
4
+
ms.date: 12/06/2022
5
5
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"]
6
6
ms.assetid: 60fb7e10-bff9-4a13-8a48-e19f25a36a02
7
7
---
8
8
# Conversions from unsigned integral types
9
9
10
10
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.
11
11
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:
13
13
14
14
```C
15
15
unsigned k = 65533;
@@ -19,7 +19,7 @@ j = k;
19
19
printf_s( "%hd\n", j ); // Prints -3
20
20
```
21
21
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.
23
23
24
24
See [Storage of basic types](../c-language/storage-of-basic-types.md) for information about the sizes of integral and floating-point types.
25
25
@@ -33,48 +33,48 @@ The following table summarizes conversions from unsigned integral types.
33
33
34
34
## Table of conversions from unsigned integral types
35
35
36
-
|From|To|Method|
37
-
|----------|--------|------------|
38
-
|**`unsigned char`**|**`char`**|Preserve bit pattern; high-order bit becomes sign bit|
0 commit comments