pnmixer-rust/num_traits/int/trait.PrimInt.html
2017-07-15 01:30:16 +02:00

336 lines
34 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="rustdoc">
<meta name="description" content="API documentation for the Rust `PrimInt` trait in crate `num_traits`.">
<meta name="keywords" content="rust, rustlang, rust-lang, PrimInt">
<title>num_traits::int::PrimInt - Rust</title>
<link rel="stylesheet" type="text/css" href="../../normalize.css">
<link rel="stylesheet" type="text/css" href="../../rustdoc.css">
<link rel="stylesheet" type="text/css" href="../../main.css">
<link rel="shortcut icon" href="https://rust-num.github.io/num/favicon.ico">
</head>
<body class="rustdoc trait">
<!--[if lte IE 8]>
<div class="warning">
This old browser is unsupported and will most likely display funky
things.
</div>
<![endif]-->
<nav class="sidebar">
<a href='../../num_traits/index.html'><img src='https://rust-num.github.io/num/rust-logo-128x128-blk-v2.png' alt='logo' width='100'></a>
<p class='location'>Trait PrimInt</p><div class="block items"><ul><li><a href="#required-methods">Required Methods</a></li><li><a href="#implementors">Implementors</a></li></ul></div><p class='location'><a href='../index.html'>num_traits</a>::<wbr><a href='index.html'>int</a></p><script>window.sidebarCurrent = {name: 'PrimInt', ty: 'trait', relpath: ''};</script><script defer src="sidebar-items.js"></script>
</nav>
<nav class="sub">
<form class="search-form js-only">
<div class="search-container">
<input class="search-input" name="search"
autocomplete="off"
placeholder="Click or press S to search, ? for more options…"
type="search">
</div>
</form>
</nav>
<section id='main' class="content">
<h1 class='fqn'><span class='in-band'>Trait <a href='../index.html'>num_traits</a>::<wbr><a href='index.html'>int</a>::<wbr><a class="trait" href=''>PrimInt</a></span><span class='out-of-band'><span id='render-detail'>
<a id="toggle-all-docs" href="javascript:void(0)" title="collapse all docs">
[<span class='inner'>&#x2212;</span>]
</a>
</span><a class='srclink' href='../../src/num_traits/int.rs.html#8-278' title='goto source code'>[src]</a></span></h1>
<pre class='rust trait'>pub trait PrimInt: <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Sized.html" title="trait core::marker::Sized">Sized</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/marker/trait.Copy.html" title="trait core::marker::Copy">Copy</a> + <a class="trait" href="../../num_traits/trait.Num.html" title="trait num_traits::Num">Num</a> + <a class="trait" href="../../num_traits/cast/trait.NumCast.html" title="trait num_traits::cast::NumCast">NumCast</a> + <a class="trait" href="../../num_traits/bounds/trait.Bounded.html" title="trait num_traits::bounds::Bounded">Bounded</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.PartialOrd.html" title="trait core::cmp::PartialOrd">PartialOrd</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Ord.html" title="trait core::cmp::Ord">Ord</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/cmp/trait.Eq.html" title="trait core::cmp::Eq">Eq</a> + <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/bit/trait.Not.html" title="trait core::ops::bit::Not">Not</a>&lt;Output = Self&gt; + <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/bit/trait.BitAnd.html" title="trait core::ops::bit::BitAnd">BitAnd</a>&lt;Output = Self&gt; + <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/bit/trait.BitOr.html" title="trait core::ops::bit::BitOr">BitOr</a>&lt;Output = Self&gt; + <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/bit/trait.BitXor.html" title="trait core::ops::bit::BitXor">BitXor</a>&lt;Output = Self&gt; + <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/bit/trait.Shl.html" title="trait core::ops::bit::Shl">Shl</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, Output = Self&gt; + <a class="trait" href="https://doc.rust-lang.org/nightly/core/ops/bit/trait.Shr.html" title="trait core::ops::bit::Shr">Shr</a>&lt;<a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a>, Output = Self&gt; + <a class="trait" href="../../num_traits/ops/checked/trait.CheckedAdd.html" title="trait num_traits::ops::checked::CheckedAdd">CheckedAdd</a>&lt;Output = Self&gt; + <a class="trait" href="../../num_traits/ops/checked/trait.CheckedSub.html" title="trait num_traits::ops::checked::CheckedSub">CheckedSub</a>&lt;Output = Self&gt; + <a class="trait" href="../../num_traits/ops/checked/trait.CheckedMul.html" title="trait num_traits::ops::checked::CheckedMul">CheckedMul</a>&lt;Output = Self&gt; + <a class="trait" href="../../num_traits/ops/checked/trait.CheckedDiv.html" title="trait num_traits::ops::checked::CheckedDiv">CheckedDiv</a>&lt;Output = Self&gt; + <a class="trait" href="../../num_traits/ops/saturating/trait.Saturating.html" title="trait num_traits::ops::saturating::Saturating">Saturating</a> {
fn <a href='#tymethod.count_ones' class='fnname'>count_ones</a>(self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>;
fn <a href='#tymethod.count_zeros' class='fnname'>count_zeros</a>(self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>;
fn <a href='#tymethod.leading_zeros' class='fnname'>leading_zeros</a>(self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>;
fn <a href='#tymethod.trailing_zeros' class='fnname'>trailing_zeros</a>(self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>;
fn <a href='#tymethod.rotate_left' class='fnname'>rotate_left</a>(self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -&gt; Self;
fn <a href='#tymethod.rotate_right' class='fnname'>rotate_right</a>(self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -&gt; Self;
fn <a href='#tymethod.signed_shl' class='fnname'>signed_shl</a>(self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -&gt; Self;
fn <a href='#tymethod.signed_shr' class='fnname'>signed_shr</a>(self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -&gt; Self;
fn <a href='#tymethod.unsigned_shl' class='fnname'>unsigned_shl</a>(self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -&gt; Self;
fn <a href='#tymethod.unsigned_shr' class='fnname'>unsigned_shr</a>(self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -&gt; Self;
fn <a href='#tymethod.swap_bytes' class='fnname'>swap_bytes</a>(self) -&gt; Self;
fn <a href='#tymethod.from_be' class='fnname'>from_be</a>(x: Self) -&gt; Self;
fn <a href='#tymethod.from_le' class='fnname'>from_le</a>(x: Self) -&gt; Self;
fn <a href='#tymethod.to_be' class='fnname'>to_be</a>(self) -&gt; Self;
fn <a href='#tymethod.to_le' class='fnname'>to_le</a>(self) -&gt; Self;
fn <a href='#tymethod.pow' class='fnname'>pow</a>(self, exp: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -&gt; Self;
}</pre>
<h2 id='required-methods'>Required Methods</h2>
<div class='methods'>
<h3 id='tymethod.count_ones' class='method'><span id='count_ones.v' class='invisible'><code>fn <a href='#tymethod.count_ones' class='fnname'>count_ones</a>(self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a></code></span></h3><div class='docblock'><p>Returns the number of ones in the binary representation of <code>self</code>.</p>
<h1 id='examples' class='section-header'><a href='#examples'>Examples</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">PrimInt</span>;
<span class="kw">let</span> <span class="ident">n</span> <span class="op">=</span> <span class="number">0b01001100u8</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">n</span>.<span class="ident">count_ones</span>(), <span class="number">3</span>);<a class="test-arrow" target="_blank" href="http://play.integer32.com/?code=extern%20crate%20num_traits%3B%0Afn%20main()%20%7B%0Ause%20num_traits%3A%3APrimInt%3B%0A%0Alet%20n%20%3D%200b01001100u8%3B%0A%0Aassert_eq!(n.count_ones()%2C%203)%3B%0A%7D">Run</a></pre>
</div><h3 id='tymethod.count_zeros' class='method'><span id='count_zeros.v' class='invisible'><code>fn <a href='#tymethod.count_zeros' class='fnname'>count_zeros</a>(self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a></code></span></h3><div class='docblock'><p>Returns the number of zeros in the binary representation of <code>self</code>.</p>
<h1 id='examples-1' class='section-header'><a href='#examples-1'>Examples</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">PrimInt</span>;
<span class="kw">let</span> <span class="ident">n</span> <span class="op">=</span> <span class="number">0b01001100u8</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">n</span>.<span class="ident">count_zeros</span>(), <span class="number">5</span>);<a class="test-arrow" target="_blank" href="http://play.integer32.com/?code=extern%20crate%20num_traits%3B%0Afn%20main()%20%7B%0Ause%20num_traits%3A%3APrimInt%3B%0A%0Alet%20n%20%3D%200b01001100u8%3B%0A%0Aassert_eq!(n.count_zeros()%2C%205)%3B%0A%7D">Run</a></pre>
</div><h3 id='tymethod.leading_zeros' class='method'><span id='leading_zeros.v' class='invisible'><code>fn <a href='#tymethod.leading_zeros' class='fnname'>leading_zeros</a>(self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a></code></span></h3><div class='docblock'><p>Returns the number of leading zeros in the binary representation
of <code>self</code>.</p>
<h1 id='examples-2' class='section-header'><a href='#examples-2'>Examples</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">PrimInt</span>;
<span class="kw">let</span> <span class="ident">n</span> <span class="op">=</span> <span class="number">0b0101000u16</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">n</span>.<span class="ident">leading_zeros</span>(), <span class="number">10</span>);<a class="test-arrow" target="_blank" href="http://play.integer32.com/?code=extern%20crate%20num_traits%3B%0Afn%20main()%20%7B%0Ause%20num_traits%3A%3APrimInt%3B%0A%0Alet%20n%20%3D%200b0101000u16%3B%0A%0Aassert_eq!(n.leading_zeros()%2C%2010)%3B%0A%7D">Run</a></pre>
</div><h3 id='tymethod.trailing_zeros' class='method'><span id='trailing_zeros.v' class='invisible'><code>fn <a href='#tymethod.trailing_zeros' class='fnname'>trailing_zeros</a>(self) -&gt; <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a></code></span></h3><div class='docblock'><p>Returns the number of trailing zeros in the binary representation
of <code>self</code>.</p>
<h1 id='examples-3' class='section-header'><a href='#examples-3'>Examples</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">PrimInt</span>;
<span class="kw">let</span> <span class="ident">n</span> <span class="op">=</span> <span class="number">0b0101000u16</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">n</span>.<span class="ident">trailing_zeros</span>(), <span class="number">3</span>);<a class="test-arrow" target="_blank" href="http://play.integer32.com/?code=extern%20crate%20num_traits%3B%0Afn%20main()%20%7B%0Ause%20num_traits%3A%3APrimInt%3B%0A%0Alet%20n%20%3D%200b0101000u16%3B%0A%0Aassert_eq!(n.trailing_zeros()%2C%203)%3B%0A%7D">Run</a></pre>
</div><h3 id='tymethod.rotate_left' class='method'><span id='rotate_left.v' class='invisible'><code>fn <a href='#tymethod.rotate_left' class='fnname'>rotate_left</a>(self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -&gt; Self</code></span></h3><div class='docblock'><p>Shifts the bits to the left by a specified amount amount, <code>n</code>, wrapping
the truncated bits to the end of the resulting integer.</p>
<h1 id='examples-4' class='section-header'><a href='#examples-4'>Examples</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">PrimInt</span>;
<span class="kw">let</span> <span class="ident">n</span> <span class="op">=</span> <span class="number">0x0123456789ABCDEFu64</span>;
<span class="kw">let</span> <span class="ident">m</span> <span class="op">=</span> <span class="number">0x3456789ABCDEF012u64</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">n</span>.<span class="ident">rotate_left</span>(<span class="number">12</span>), <span class="ident">m</span>);<a class="test-arrow" target="_blank" href="http://play.integer32.com/?code=extern%20crate%20num_traits%3B%0Afn%20main()%20%7B%0Ause%20num_traits%3A%3APrimInt%3B%0A%0Alet%20n%20%3D%200x0123456789ABCDEFu64%3B%0Alet%20m%20%3D%200x3456789ABCDEF012u64%3B%0A%0Aassert_eq!(n.rotate_left(12)%2C%20m)%3B%0A%7D">Run</a></pre>
</div><h3 id='tymethod.rotate_right' class='method'><span id='rotate_right.v' class='invisible'><code>fn <a href='#tymethod.rotate_right' class='fnname'>rotate_right</a>(self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -&gt; Self</code></span></h3><div class='docblock'><p>Shifts the bits to the right by a specified amount amount, <code>n</code>, wrapping
the truncated bits to the beginning of the resulting integer.</p>
<h1 id='examples-5' class='section-header'><a href='#examples-5'>Examples</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">PrimInt</span>;
<span class="kw">let</span> <span class="ident">n</span> <span class="op">=</span> <span class="number">0x0123456789ABCDEFu64</span>;
<span class="kw">let</span> <span class="ident">m</span> <span class="op">=</span> <span class="number">0xDEF0123456789ABCu64</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">n</span>.<span class="ident">rotate_right</span>(<span class="number">12</span>), <span class="ident">m</span>);<a class="test-arrow" target="_blank" href="http://play.integer32.com/?code=extern%20crate%20num_traits%3B%0Afn%20main()%20%7B%0Ause%20num_traits%3A%3APrimInt%3B%0A%0Alet%20n%20%3D%200x0123456789ABCDEFu64%3B%0Alet%20m%20%3D%200xDEF0123456789ABCu64%3B%0A%0Aassert_eq!(n.rotate_right(12)%2C%20m)%3B%0A%7D">Run</a></pre>
</div><h3 id='tymethod.signed_shl' class='method'><span id='signed_shl.v' class='invisible'><code>fn <a href='#tymethod.signed_shl' class='fnname'>signed_shl</a>(self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -&gt; Self</code></span></h3><div class='docblock'><p>Shifts the bits to the left by a specified amount amount, <code>n</code>, filling
zeros in the least significant bits.</p>
<p>This is bitwise equivalent to signed <code>Shl</code>.</p>
<h1 id='examples-6' class='section-header'><a href='#examples-6'>Examples</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">PrimInt</span>;
<span class="kw">let</span> <span class="ident">n</span> <span class="op">=</span> <span class="number">0x0123456789ABCDEFu64</span>;
<span class="kw">let</span> <span class="ident">m</span> <span class="op">=</span> <span class="number">0x3456789ABCDEF000u64</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">n</span>.<span class="ident">signed_shl</span>(<span class="number">12</span>), <span class="ident">m</span>);<a class="test-arrow" target="_blank" href="http://play.integer32.com/?code=extern%20crate%20num_traits%3B%0Afn%20main()%20%7B%0Ause%20num_traits%3A%3APrimInt%3B%0A%0Alet%20n%20%3D%200x0123456789ABCDEFu64%3B%0Alet%20m%20%3D%200x3456789ABCDEF000u64%3B%0A%0Aassert_eq!(n.signed_shl(12)%2C%20m)%3B%0A%7D">Run</a></pre>
</div><h3 id='tymethod.signed_shr' class='method'><span id='signed_shr.v' class='invisible'><code>fn <a href='#tymethod.signed_shr' class='fnname'>signed_shr</a>(self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -&gt; Self</code></span></h3><div class='docblock'><p>Shifts the bits to the right by a specified amount amount, <code>n</code>, copying
the &quot;sign bit&quot; in the most significant bits even for unsigned types.</p>
<p>This is bitwise equivalent to signed <code>Shr</code>.</p>
<h1 id='examples-7' class='section-header'><a href='#examples-7'>Examples</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">PrimInt</span>;
<span class="kw">let</span> <span class="ident">n</span> <span class="op">=</span> <span class="number">0xFEDCBA9876543210u64</span>;
<span class="kw">let</span> <span class="ident">m</span> <span class="op">=</span> <span class="number">0xFFFFEDCBA9876543u64</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">n</span>.<span class="ident">signed_shr</span>(<span class="number">12</span>), <span class="ident">m</span>);<a class="test-arrow" target="_blank" href="http://play.integer32.com/?code=extern%20crate%20num_traits%3B%0Afn%20main()%20%7B%0Ause%20num_traits%3A%3APrimInt%3B%0A%0Alet%20n%20%3D%200xFEDCBA9876543210u64%3B%0Alet%20m%20%3D%200xFFFFEDCBA9876543u64%3B%0A%0Aassert_eq!(n.signed_shr(12)%2C%20m)%3B%0A%7D">Run</a></pre>
</div><h3 id='tymethod.unsigned_shl' class='method'><span id='unsigned_shl.v' class='invisible'><code>fn <a href='#tymethod.unsigned_shl' class='fnname'>unsigned_shl</a>(self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -&gt; Self</code></span></h3><div class='docblock'><p>Shifts the bits to the left by a specified amount amount, <code>n</code>, filling
zeros in the least significant bits.</p>
<p>This is bitwise equivalent to unsigned <code>Shl</code>.</p>
<h1 id='examples-8' class='section-header'><a href='#examples-8'>Examples</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">PrimInt</span>;
<span class="kw">let</span> <span class="ident">n</span> <span class="op">=</span> <span class="number">0x0123456789ABCDEFi64</span>;
<span class="kw">let</span> <span class="ident">m</span> <span class="op">=</span> <span class="number">0x3456789ABCDEF000i64</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">n</span>.<span class="ident">unsigned_shl</span>(<span class="number">12</span>), <span class="ident">m</span>);<a class="test-arrow" target="_blank" href="http://play.integer32.com/?code=extern%20crate%20num_traits%3B%0Afn%20main()%20%7B%0Ause%20num_traits%3A%3APrimInt%3B%0A%0Alet%20n%20%3D%200x0123456789ABCDEFi64%3B%0Alet%20m%20%3D%200x3456789ABCDEF000i64%3B%0A%0Aassert_eq!(n.unsigned_shl(12)%2C%20m)%3B%0A%7D">Run</a></pre>
</div><h3 id='tymethod.unsigned_shr' class='method'><span id='unsigned_shr.v' class='invisible'><code>fn <a href='#tymethod.unsigned_shr' class='fnname'>unsigned_shr</a>(self, n: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -&gt; Self</code></span></h3><div class='docblock'><p>Shifts the bits to the right by a specified amount amount, <code>n</code>, filling
zeros in the most significant bits.</p>
<p>This is bitwise equivalent to unsigned <code>Shr</code>.</p>
<h1 id='examples-9' class='section-header'><a href='#examples-9'>Examples</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">PrimInt</span>;
<span class="kw">let</span> <span class="ident">n</span> <span class="op">=</span> <span class="number">0xFEDCBA9876543210i64</span>;
<span class="kw">let</span> <span class="ident">m</span> <span class="op">=</span> <span class="number">0x000FEDCBA9876543i64</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">n</span>.<span class="ident">unsigned_shr</span>(<span class="number">12</span>), <span class="ident">m</span>);<a class="test-arrow" target="_blank" href="http://play.integer32.com/?code=extern%20crate%20num_traits%3B%0Afn%20main()%20%7B%0Ause%20num_traits%3A%3APrimInt%3B%0A%0Alet%20n%20%3D%200xFEDCBA9876543210i64%3B%0Alet%20m%20%3D%200x000FEDCBA9876543i64%3B%0A%0Aassert_eq!(n.unsigned_shr(12)%2C%20m)%3B%0A%7D">Run</a></pre>
</div><h3 id='tymethod.swap_bytes' class='method'><span id='swap_bytes.v' class='invisible'><code>fn <a href='#tymethod.swap_bytes' class='fnname'>swap_bytes</a>(self) -&gt; Self</code></span></h3><div class='docblock'><p>Reverses the byte order of the integer.</p>
<h1 id='examples-10' class='section-header'><a href='#examples-10'>Examples</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">PrimInt</span>;
<span class="kw">let</span> <span class="ident">n</span> <span class="op">=</span> <span class="number">0x0123456789ABCDEFu64</span>;
<span class="kw">let</span> <span class="ident">m</span> <span class="op">=</span> <span class="number">0xEFCDAB8967452301u64</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">n</span>.<span class="ident">swap_bytes</span>(), <span class="ident">m</span>);<a class="test-arrow" target="_blank" href="http://play.integer32.com/?code=extern%20crate%20num_traits%3B%0Afn%20main()%20%7B%0Ause%20num_traits%3A%3APrimInt%3B%0A%0Alet%20n%20%3D%200x0123456789ABCDEFu64%3B%0Alet%20m%20%3D%200xEFCDAB8967452301u64%3B%0A%0Aassert_eq!(n.swap_bytes()%2C%20m)%3B%0A%7D">Run</a></pre>
</div><h3 id='tymethod.from_be' class='method'><span id='from_be.v' class='invisible'><code>fn <a href='#tymethod.from_be' class='fnname'>from_be</a>(x: Self) -&gt; Self</code></span></h3><div class='docblock'><p>Convert an integer from big endian to the target&#39;s endianness.</p>
<p>On big endian this is a no-op. On little endian the bytes are swapped.</p>
<h1 id='examples-11' class='section-header'><a href='#examples-11'>Examples</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">PrimInt</span>;
<span class="kw">let</span> <span class="ident">n</span> <span class="op">=</span> <span class="number">0x0123456789ABCDEFu64</span>;
<span class="kw">if</span> <span class="macro">cfg</span><span class="macro">!</span>(<span class="ident">target_endian</span> <span class="op">=</span> <span class="string">&quot;big&quot;</span>) {
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">u64</span>::<span class="ident">from_be</span>(<span class="ident">n</span>), <span class="ident">n</span>)
} <span class="kw">else</span> {
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">u64</span>::<span class="ident">from_be</span>(<span class="ident">n</span>), <span class="ident">n</span>.<span class="ident">swap_bytes</span>())
}<a class="test-arrow" target="_blank" href="http://play.integer32.com/?code=extern%20crate%20num_traits%3B%0Afn%20main()%20%7B%0Ause%20num_traits%3A%3APrimInt%3B%0A%0Alet%20n%20%3D%200x0123456789ABCDEFu64%3B%0A%0Aif%20cfg!(target_endian%20%3D%20%22big%22)%20%7B%0A%20%20%20%20assert_eq!(u64%3A%3Afrom_be(n)%2C%20n)%0A%7D%20else%20%7B%0A%20%20%20%20assert_eq!(u64%3A%3Afrom_be(n)%2C%20n.swap_bytes())%0A%7D%0A%7D">Run</a></pre>
</div><h3 id='tymethod.from_le' class='method'><span id='from_le.v' class='invisible'><code>fn <a href='#tymethod.from_le' class='fnname'>from_le</a>(x: Self) -&gt; Self</code></span></h3><div class='docblock'><p>Convert an integer from little endian to the target&#39;s endianness.</p>
<p>On little endian this is a no-op. On big endian the bytes are swapped.</p>
<h1 id='examples-12' class='section-header'><a href='#examples-12'>Examples</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">PrimInt</span>;
<span class="kw">let</span> <span class="ident">n</span> <span class="op">=</span> <span class="number">0x0123456789ABCDEFu64</span>;
<span class="kw">if</span> <span class="macro">cfg</span><span class="macro">!</span>(<span class="ident">target_endian</span> <span class="op">=</span> <span class="string">&quot;little&quot;</span>) {
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">u64</span>::<span class="ident">from_le</span>(<span class="ident">n</span>), <span class="ident">n</span>)
} <span class="kw">else</span> {
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">u64</span>::<span class="ident">from_le</span>(<span class="ident">n</span>), <span class="ident">n</span>.<span class="ident">swap_bytes</span>())
}<a class="test-arrow" target="_blank" href="http://play.integer32.com/?code=extern%20crate%20num_traits%3B%0Afn%20main()%20%7B%0Ause%20num_traits%3A%3APrimInt%3B%0A%0Alet%20n%20%3D%200x0123456789ABCDEFu64%3B%0A%0Aif%20cfg!(target_endian%20%3D%20%22little%22)%20%7B%0A%20%20%20%20assert_eq!(u64%3A%3Afrom_le(n)%2C%20n)%0A%7D%20else%20%7B%0A%20%20%20%20assert_eq!(u64%3A%3Afrom_le(n)%2C%20n.swap_bytes())%0A%7D%0A%7D">Run</a></pre>
</div><h3 id='tymethod.to_be' class='method'><span id='to_be.v' class='invisible'><code>fn <a href='#tymethod.to_be' class='fnname'>to_be</a>(self) -&gt; Self</code></span></h3><div class='docblock'><p>Convert <code>self</code> to big endian from the target&#39;s endianness.</p>
<p>On big endian this is a no-op. On little endian the bytes are swapped.</p>
<h1 id='examples-13' class='section-header'><a href='#examples-13'>Examples</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">PrimInt</span>;
<span class="kw">let</span> <span class="ident">n</span> <span class="op">=</span> <span class="number">0x0123456789ABCDEFu64</span>;
<span class="kw">if</span> <span class="macro">cfg</span><span class="macro">!</span>(<span class="ident">target_endian</span> <span class="op">=</span> <span class="string">&quot;big&quot;</span>) {
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">n</span>.<span class="ident">to_be</span>(), <span class="ident">n</span>)
} <span class="kw">else</span> {
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">n</span>.<span class="ident">to_be</span>(), <span class="ident">n</span>.<span class="ident">swap_bytes</span>())
}<a class="test-arrow" target="_blank" href="http://play.integer32.com/?code=extern%20crate%20num_traits%3B%0Afn%20main()%20%7B%0Ause%20num_traits%3A%3APrimInt%3B%0A%0Alet%20n%20%3D%200x0123456789ABCDEFu64%3B%0A%0Aif%20cfg!(target_endian%20%3D%20%22big%22)%20%7B%0A%20%20%20%20assert_eq!(n.to_be()%2C%20n)%0A%7D%20else%20%7B%0A%20%20%20%20assert_eq!(n.to_be()%2C%20n.swap_bytes())%0A%7D%0A%7D">Run</a></pre>
</div><h3 id='tymethod.to_le' class='method'><span id='to_le.v' class='invisible'><code>fn <a href='#tymethod.to_le' class='fnname'>to_le</a>(self) -&gt; Self</code></span></h3><div class='docblock'><p>Convert <code>self</code> to little endian from the target&#39;s endianness.</p>
<p>On little endian this is a no-op. On big endian the bytes are swapped.</p>
<h1 id='examples-14' class='section-header'><a href='#examples-14'>Examples</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">PrimInt</span>;
<span class="kw">let</span> <span class="ident">n</span> <span class="op">=</span> <span class="number">0x0123456789ABCDEFu64</span>;
<span class="kw">if</span> <span class="macro">cfg</span><span class="macro">!</span>(<span class="ident">target_endian</span> <span class="op">=</span> <span class="string">&quot;little&quot;</span>) {
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">n</span>.<span class="ident">to_le</span>(), <span class="ident">n</span>)
} <span class="kw">else</span> {
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">n</span>.<span class="ident">to_le</span>(), <span class="ident">n</span>.<span class="ident">swap_bytes</span>())
}<a class="test-arrow" target="_blank" href="http://play.integer32.com/?code=extern%20crate%20num_traits%3B%0Afn%20main()%20%7B%0Ause%20num_traits%3A%3APrimInt%3B%0A%0Alet%20n%20%3D%200x0123456789ABCDEFu64%3B%0A%0Aif%20cfg!(target_endian%20%3D%20%22little%22)%20%7B%0A%20%20%20%20assert_eq!(n.to_le()%2C%20n)%0A%7D%20else%20%7B%0A%20%20%20%20assert_eq!(n.to_le()%2C%20n.swap_bytes())%0A%7D%0A%7D">Run</a></pre>
</div><h3 id='tymethod.pow' class='method'><span id='pow.v' class='invisible'><code>fn <a href='#tymethod.pow' class='fnname'>pow</a>(self, exp: <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a>) -&gt; Self</code></span></h3><div class='docblock'><p>Raises self to the power of <code>exp</code>, using exponentiation by squaring.</p>
<h1 id='examples-15' class='section-header'><a href='#examples-15'>Examples</a></h1>
<pre class="rust rust-example-rendered">
<span class="kw">use</span> <span class="ident">num_traits</span>::<span class="ident">PrimInt</span>;
<span class="macro">assert_eq</span><span class="macro">!</span>(<span class="number">2i32</span>.<span class="ident">pow</span>(<span class="number">4</span>), <span class="number">16</span>);<a class="test-arrow" target="_blank" href="http://play.integer32.com/?code=extern%20crate%20num_traits%3B%0Afn%20main()%20%7B%0Ause%20num_traits%3A%3APrimInt%3B%0A%0Aassert_eq!(2i32.pow(4)%2C%2016)%3B%0A%7D">Run</a></pre>
</div></div>
<h2 id='implementors'>Implementors</h2>
<ul class='item-list' id='implementors-list'>
<li><code>impl PrimInt for <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u8.html">u8</a></code></li>
<li><code>impl PrimInt for <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u16.html">u16</a></code></li>
<li><code>impl PrimInt for <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u32.html">u32</a></code></li>
<li><code>impl PrimInt for <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.u64.html">u64</a></code></li>
<li><code>impl PrimInt for <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.usize.html">usize</a></code></li>
<li><code>impl PrimInt for <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i8.html">i8</a></code></li>
<li><code>impl PrimInt for <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i16.html">i16</a></code></li>
<li><code>impl PrimInt for <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i32.html">i32</a></code></li>
<li><code>impl PrimInt for <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.i64.html">i64</a></code></li>
<li><code>impl PrimInt for <a class="primitive" href="https://doc.rust-lang.org/nightly/std/primitive.isize.html">isize</a></code></li>
</ul><script type="text/javascript" async
src="../../implementors/num_traits/int/trait.PrimInt.js">
</script></section>
<section id='search' class="content hidden"></section>
<section class="footer"></section>
<aside id="help" class="hidden">
<div>
<h1 class="hidden">Help</h1>
<div class="shortcuts">
<h2>Keyboard Shortcuts</h2>
<dl>
<dt>?</dt>
<dd>Show this help dialog</dd>
<dt>S</dt>
<dd>Focus the search field</dd>
<dt>&larrb;</dt>
<dd>Move up in search results</dd>
<dt>&rarrb;</dt>
<dd>Move down in search results</dd>
<dt>&#9166;</dt>
<dd>Go to active search result</dd>
<dt>+</dt>
<dd>Collapse/expand all sections</dd>
</dl>
</div>
<div class="infos">
<h2>Search Tricks</h2>
<p>
Prefix searches with a type followed by a colon (e.g.
<code>fn:</code>) to restrict the search to a given type.
</p>
<p>
Accepted types are: <code>fn</code>, <code>mod</code>,
<code>struct</code>, <code>enum</code>,
<code>trait</code>, <code>type</code>, <code>macro</code>,
and <code>const</code>.
</p>
<p>
Search functions by type signature (e.g.
<code>vec -> usize</code> or <code>* -> vec</code>)
</p>
</div>
</div>
</aside>
<script>
window.rootPath = "../../";
window.currentCrate = "num_traits";
</script>
<script src="../../main.js"></script>
<script defer src="../../search-index.js"></script>
</body>
</html>