about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2017-12-17 16:02:11 -0500
committerCorey Farwell <coreyf@rwell.org>2017-12-17 16:02:11 -0500
commit05cb6a5857a0b3966dfb48e6cc779b6a2137d6c6 (patch)
tree31a95310cef0002e937a85a62df2119d77830287
parent4f2ef415ba1e64d843ee58e95009871053d3f7a6 (diff)
downloadrust-05cb6a5857a0b3966dfb48e6cc779b6a2137d6c6.tar.gz
rust-05cb6a5857a0b3966dfb48e6cc779b6a2137d6c6.zip
Display binary notation for numeric swap_bytes methods.
This better illustrates what's happening to the bits behind the scenes.
-rw-r--r--src/libcore/num/mod.rs18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs
index 9ee86d0f1a0..245ca83f28f 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]