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
Low-level code often needs to interpret an object of one type as another type. The reinterpreted object has the same bit representation as the original, but is a different type. But making the bit-for-bit conversion can be error-prone.
76
+
Low-level code often needs to interpret an object of one type as another type. The reinterpreted object has the same bit representation as the original, but is a different type.
77
77
78
78
Instead of using `reinterpret_cast`, or `memcpy()`, `bit_cast()` is a better way to make these conversions. It's better because:
79
79
-`bit_cast()` is `constexpr`
80
-
-`bit_cast()` requires the types to be trivially copyable and the same size. This prevents potential problems with using `reinterpret_cast` and `memcpy` because they could be used to inadvertently, and incorrectly, convert non-trivially-copyable types. Also, `memcpy()` could be used to inadvertently copy between types that aren't the same size. For example, a double (8 bytes) into an unsigned int (4 bytes), or the other way around.
80
+
-`bit_cast()` requires the types to be trivially copyable and the same size. This prevents potential problems that you could encounter using `reinterpret_cast` and `memcpy` because they could be used to inadvertently, and incorrectly, convert non-trivially-copyable types. Also, `memcpy()` could be used to inadvertently copy between types that aren't the same size. For example, a double (8 bytes) into an unsigned int (4 bytes), or the other way around.
81
81
82
82
This overload only participates in overload resolution if:
83
83
-`sizeof(To) == sizeof(From)`
@@ -208,7 +208,7 @@ The unsigned integer value to test.
208
208
209
209
### Return Value
210
210
211
-
The number of bits needed to store `value`.
211
+
The number of bits needed to represent `value`.
212
212
213
213
If `value` is zero, returns zero.
214
214
@@ -458,7 +458,7 @@ This template function only participates in overload resolution if `T` is an uns
458
458
459
459
## <aname="has_single_bit"></a>`has_single_bit`
460
460
461
-
Check if a value has only one bit set (which means it is a power of two).
461
+
Check if a value has only one bit set.This is the same as testing whether a value is a power of two.
462
462
463
463
```cpp
464
464
template <classT>
@@ -472,7 +472,7 @@ The unsigned integer value to test.
472
472
473
473
### Return value
474
474
475
-
`true` if `value` has only one bit set (which means it is a power of two). Otherwise, `false`.
475
+
`true` if `value` has only one bit set which also means that `value` is a power of two. Otherwise, `false`.
476
476
477
477
### Example
478
478
@@ -512,7 +512,7 @@ This template function only participates in overload resolution if `T` is an uns
512
512
513
513
## <aname="popcount"></a>`popcount`
514
514
515
-
Count the number of set bits in an unsigned integer value.
515
+
Count the number of bits set to one in an unsigned integer value.
516
516
517
517
```cpp
518
518
template<classT>
@@ -526,7 +526,7 @@ The unsigned integer value to test.
526
526
527
527
### Return value
528
528
529
-
The number of set bits in `value`.
529
+
The number bits set to one in `value`.
530
530
531
531
### Example
532
532
@@ -584,7 +584,7 @@ nodiscard constexpr T rotl(T value, int s) noexcept;
Copy file name to clipboardExpand all lines: docs/standard-library/bit.md
+10-10Lines changed: 10 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: "<bit>"
3
3
description: "Functions to access, manipulate, and process individual bits and sequences of bits."
4
-
ms.date: "08/27/2020"
4
+
ms.date: "08/28/2020"
5
5
f1_keywords: ["<bit>"]
6
6
helpviewer_keywords: ["bit header"]
7
7
---
@@ -32,18 +32,18 @@ For example, there are functions to rotate bits, find the number of consecutive
32
32
33
33
| Function | Description |
34
34
|-----|-----|
35
-
|[bit_cast](bit-functions.md#bit_cast)| Reinterpret the object representation of one type to another. |
36
-
|[bit_ceil](bit-functions.md#bit_ceil)| Find the smallest power of two greater than or equal to the given value. |
37
-
|[bit_floor](bit-functions.md#bit_floor)| Find the largest integral power of two not greater than the given value. |
38
-
|[bit_width](bit-functions.md#bit_width)| Find the smallest number of bits needed to represent the given value. |
39
-
|[countl_zero](bit-functions.md#countl_zero)| Count the number of consecutive zero bits, starting from the most significant bit. |
35
+
|[bit_cast](bit-functions.md#bit_cast)| Reinterpret the object representation from one type to another. |
36
+
|[bit_ceil](bit-functions.md#bit_ceil)| Find the smallest power of two greater than or equal to a value. |
37
+
|[bit_floor](bit-functions.md#bit_floor)| Find the largest integral power of two not greater than a value. |
38
+
|[bit_width](bit-functions.md#bit_width)| Find the smallest number of bits needed to represent a value. |
39
+
|[countl_zero](bit-functions.md#countl_zero)| Count the number of consecutive bits set to zero, starting from the most significant bit. |
40
40
|[countl_one](bit-functions.md#countl_one)| Count the number of consecutive bits set to one, starting from the most significant bit. |
41
41
|[countr_zero](bit-functions.md#countr_zero)| Count the number of consecutive bits set to zero, starting from the least significant bit. |
42
42
|[countr_one](bit-functions.md#countl_one)| Count the number of consecutive bits set to one, starting from the least significant bit. |
43
-
|[has_single_bit](bit-functions.md#has_single_bit)| Check if a value has only a single bit set; that is, if the value is an integral power of two. |
44
-
|[popcount](bit-functions.md#popcount)| Count the number of bits set to one in an unsigned integer. |
45
-
|[rotl](bit-functions.md#rotl)| Compute the result of bitwise left-rotation. |
46
-
|[rotr](bit-functions.md#rotr)| Compute the result of bitwise right-rotation. |
43
+
|[has_single_bit](bit-functions.md#has_single_bit)| Check if a value has only one bit set. This isthe same as testing whether a value is a power of two. |
44
+
|[popcount](bit-functions.md#popcount)| Count the number of bits set to one. |
45
+
|[rotl](bit-functions.md#rotl)| Compute the result of a bitwise left-rotation. |
46
+
|[rotr](bit-functions.md#rotr)| Compute the result of a bitwise right-rotation. |
0 commit comments