File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -218,6 +218,24 @@ pub trait PrimInt:
218
218
/// ```
219
219
fn swap_bytes ( self ) -> Self ;
220
220
221
+ /// Reverses the order of bits in the integer.
222
+ ///
223
+ /// The least significant bit becomes the most significant bit, second least-significant bit
224
+ /// becomes second most-significant bit, etc.
225
+ ///
226
+ /// # Examples
227
+ ///
228
+ /// ```
229
+ /// use num_traits::PrimInt;
230
+ ///
231
+ /// let n = 0x12345678u32;
232
+ /// let m = 0x1e6a2c48u32;
233
+ ///
234
+ /// assert_eq!(n.reverse_bits(), m);
235
+ /// assert_eq!(0u32.reverse_bits(), 0);
236
+ /// ```
237
+ fn reverse_bits ( self ) -> Self ;
238
+
221
239
/// Convert an integer from big endian to the target's endianness.
222
240
///
223
241
/// On big endian this is a no-op. On little endian the bytes are swapped.
@@ -364,6 +382,11 @@ macro_rules! prim_int_impl {
364
382
<$T>:: swap_bytes( self )
365
383
}
366
384
385
+ #[ inline]
386
+ fn reverse_bits( self ) -> Self {
387
+ <$T>:: reverse_bits( self )
388
+ }
389
+
367
390
#[ inline]
368
391
fn from_be( x: Self ) -> Self {
369
392
<$T>:: from_be( x)
You can’t perform that action at this time.
0 commit comments