From 05cb6a5857a0b3966dfb48e6cc779b6a2137d6c6 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Sun, 17 Dec 2017 16:02:11 -0500 Subject: [PATCH] Display binary notation for numeric swap_bytes methods. This better illustrates what's happening to the bits behind the scenes. --- src/libcore/num/mod.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 9ee86d0f1a0a7..245ca83f28f65 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -273,10 +273,13 @@ macro_rules! int_impl { /// Basic usage: /// /// ``` - /// let n = 0x0123456789ABCDEFi64; - /// let m = -0x1032547698BADCFFi64; + /// let n: i16 = 0b0000000_01010101; + /// assert_eq!(n, 85); /// - /// assert_eq!(n.swap_bytes(), m); + /// let m = n.swap_bytes(); + /// + /// assert_eq!(m, 0b01010101_00000000); + /// assert_eq!(m, 21760); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] @@ -1466,10 +1469,13 @@ macro_rules! uint_impl { /// Basic usage: /// /// ``` - /// let n = 0x0123456789ABCDEFu64; - /// let m = 0xEFCDAB8967452301u64; + /// let n: u16 = 0b0000000_01010101; + /// assert_eq!(n, 85); + /// + /// let m = n.swap_bytes(); /// - /// assert_eq!(n.swap_bytes(), m); + /// assert_eq!(m, 0b01010101_00000000); + /// assert_eq!(m, 21760); /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline]