Skip to content

Commit 05cb6a5

Browse files
committed
Display binary notation for numeric swap_bytes methods.
This better illustrates what's happening to the bits behind the scenes.
1 parent 4f2ef41 commit 05cb6a5

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/libcore/num/mod.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,13 @@ macro_rules! int_impl {
273273
/// Basic usage:
274274
///
275275
/// ```
276-
/// let n = 0x0123456789ABCDEFi64;
277-
/// let m = -0x1032547698BADCFFi64;
276+
/// let n: i16 = 0b0000000_01010101;
277+
/// assert_eq!(n, 85);
278278
///
279-
/// assert_eq!(n.swap_bytes(), m);
279+
/// let m = n.swap_bytes();
280+
///
281+
/// assert_eq!(m, 0b01010101_00000000);
282+
/// assert_eq!(m, 21760);
280283
/// ```
281284
#[stable(feature = "rust1", since = "1.0.0")]
282285
#[inline]
@@ -1466,10 +1469,13 @@ macro_rules! uint_impl {
14661469
/// Basic usage:
14671470
///
14681471
/// ```
1469-
/// let n = 0x0123456789ABCDEFu64;
1470-
/// let m = 0xEFCDAB8967452301u64;
1472+
/// let n: u16 = 0b0000000_01010101;
1473+
/// assert_eq!(n, 85);
1474+
///
1475+
/// let m = n.swap_bytes();
14711476
///
1472-
/// assert_eq!(n.swap_bytes(), m);
1477+
/// assert_eq!(m, 0b01010101_00000000);
1478+
/// assert_eq!(m, 21760);
14731479
/// ```
14741480
#[stable(feature = "rust1", since = "1.0.0")]
14751481
#[inline]

0 commit comments

Comments
 (0)