mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
976 lines
108 KiB
HTML
976 lines
108 KiB
HTML
<?xml version="1.0" encoding="utf-8" ?>
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
<!-- This file is generated by Nim. -->
|
|
<html xmlns="https://www.w3.org/1999/xhtml" xml:lang="en" lang="en" data-theme="auto">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>std/bitops</title>
|
|
|
|
<!-- Google fonts -->
|
|
<link href='https://fonts.googleapis.com/css?family=Lato:400,600,900' rel='stylesheet' type='text/css'/>
|
|
<link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
|
|
|
|
<!-- Favicon -->
|
|
<link rel="shortcut icon" href="data:image/x-icon;base64,AAABAAEAEBAAAAEAIABoBAAAFgAAACgAAAAQAAAAIAAAAAEAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAUAAAAF////AP///wD///8A////AP///wD///8A////AP///wD///8A////AAAAAAIAAABbAAAAlQAAAKIAAACbAAAAmwAAAKIAAACVAAAAWwAAAAL///8A////AP///wD///8A////AAAAABQAAADAAAAAYwAAAA3///8A////AP///wD///8AAAAADQAAAGMAAADAAAAAFP///wD///8A////AP///wAAAACdAAAAOv///wD///8A////AP///wD///8A////AP///wD///8AAAAAOgAAAJ3///8A////AP///wAAAAAnAAAAcP///wAAAAAoAAAASv///wD///8A////AP///wAAAABKAAAAKP///wAAAABwAAAAJ////wD///8AAAAAgQAAABwAAACIAAAAkAAAAJMAAACtAAAAFQAAABUAAACtAAAAkwAAAJAAAACIAAAAHAAAAIH///8A////AAAAAKQAAACrAAAAaP///wD///8AAAAARQAAANIAAADSAAAARf///wD///8AAAAAaAAAAKsAAACk////AAAAADMAAACcAAAAnQAAABj///8A////AP///wAAAAAYAAAAGP///wD///8A////AAAAABgAAACdAAAAnAAAADMAAAB1AAAAwwAAAP8AAADpAAAAsQAAAE4AAAAb////AP///wAAAAAbAAAATgAAALEAAADpAAAA/wAAAMMAAAB1AAAAtwAAAOkAAAD/AAAA/wAAAP8AAADvAAAA3gAAAN4AAADeAAAA3gAAAO8AAAD/AAAA/wAAAP8AAADpAAAAtwAAAGUAAAA/AAAA3wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAAD/AAAA/wAAAP8AAADfAAAAPwAAAGX///8A////AAAAAEgAAADtAAAAvwAAAL0AAADGAAAA7wAAAO8AAADGAAAAvQAAAL8AAADtAAAASP///wD///8A////AP///wD///8AAAAAO////wD///8A////AAAAAIcAAACH////AP///wD///8AAAAAO////wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A////AP///wD///8A//8AAP//AAD4HwAA7/cAAN/7AAD//wAAoYUAAJ55AACf+QAAh+EAAAAAAADAAwAA4AcAAP5/AAD//wAA//8AAA=="/>
|
|
<link rel="icon" type="image/png" sizes="32x32" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4QQQEwksSS9ZWwAAAk1JREFUWMPtll2ITVEUx39nn/O7Y5qR8f05wtCUUr6ZIS++8pEnkZInPImneaCQ5METNdOkeFBKUhMPRIkHKfEuUZSUlGlKPN2TrgfncpvmnntnmlEyq1Z7t89/rf9a6+y99oZxGZf/XeIq61EdtgKXgdXA0xrYAvBjOIF1AI9zvjcC74BSpndrJPkBWDScTF8Aa4E3wDlgHbASaANmVqlcCnwHvgDvgVfAJ+AikAAvgfVZwLnSVZHZaOuKoQi3ZOMi4NkYkpe1p4J7A8BpYAD49hfIy/oqG0+hLomiKP2L5L+1ubn5115S+3OAn4EnwBlgMzCjyt6ZAnQCJ4A7wOs88iRJHvw50HoujuPBoCKwHWiosy8MdfZnAdcHk8dxXFJ3VQbQlCTJvRBCGdRbD4M6uc5glpY3eAihpN5S5w12diSEcCCEcKUO4ljdr15T76ur1FDDLIQQ3qv71EdDOe3Kxj3leRXyk+pxdWnFWod6Wt2bY3de3aSuUHcPBVimHs7mK9WrmeOF6lR1o9qnzskh2ar2qm1qizpfXaPeVGdlmGN5pb09qMxz1Xb1kLqgzn1RyH7JUXW52lr5e/Kqi9qpto7V1atuUzfnARrV7jEib1T76gG2qxdGmXyiekkt1GswPTtek0aBfJp6YySGBfWg2tPQ0FAYgf1stUfdmdcjarbYJEniKIq6gY/Aw+zWHAC+p2labGpqiorFYgGYCEzN7oQdQClN07O1/EfDyGgC0ALMBdYAi4FyK+4H3gLPsxfR1zRNi+NP7nH5J+QntnXe5B5mpfQAAAAASUVORK5CYII=">
|
|
|
|
<!-- CSS -->
|
|
<link rel="stylesheet" type="text/css" href="nimdoc.out.css?v=2.3.1">
|
|
|
|
<!-- JS -->
|
|
<script type="text/javascript" src="dochack.js?v=2.3.1"></script>
|
|
</head>
|
|
<body>
|
|
<div class="document" id="documentId">
|
|
<div class="container">
|
|
<h1 class="title">std/bitops</h1>
|
|
<div class="row">
|
|
<div class="three columns">
|
|
<div class="theme-select-wrapper">
|
|
<label for="theme-select">Theme: </label>
|
|
<select id="theme-select" onchange="setTheme(this.value)">
|
|
<option value="auto">🌗 Match OS</option>
|
|
<option value="dark">🌑 Dark</option>
|
|
<option value="light">🌕 Light</option>
|
|
</select>
|
|
</div>
|
|
<div id="global-links">
|
|
<ul class="simple-boot">
|
|
<li><a href="manual.html">Manual</a></li>
|
|
<li><a href="lib.html">Standard library</a></li>
|
|
<li> <a id="indexLink" href="theindex.html">Index</a></li>
|
|
<li><a href="compiler/theindex.html">Compiler docs</a></li>
|
|
<li><a href="https://nim-lang.github.io/fusion/theindex.html">Fusion docs</a></li>
|
|
<li><a href="https://nim-lang.github.io/Nim/">devel</a>, <a href="https://nim-lang.org/documentation.html">stable</a></li>
|
|
</ul>
|
|
</div>
|
|
<div id="searchInputDiv">
|
|
Search: <input type="search" id="searchInput"
|
|
oninput="search()" />
|
|
</div>
|
|
|
|
<ul class="simple simple-toc" id="toc-list">
|
|
<li>
|
|
<a class="reference reference-toplevel" href="#6" id="56">Imports</a>
|
|
</li>
|
|
<li>
|
|
<details open>
|
|
<summary><a class="reference reference-toplevel" href="#7" id="57">Types</a></summary>
|
|
<ul class="simple simple-toc-section">
|
|
<li><a class="reference" href="#BitsRange" title="BitsRange[T] = range[0 .. sizeof(T) * 8 - 1]">BitsRange</a></li>
|
|
|
|
</ul>
|
|
</details>
|
|
</li>
|
|
<li>
|
|
<details open>
|
|
<summary><a class="reference reference-toplevel" href="#12" id="62">Procs</a></summary>
|
|
<ul class="simple simple-toc-section">
|
|
<ul class="simple nested-toc-section">bitnot
|
|
<li><a class="reference" href="#bitnot%2CT" title="bitnot[T: SomeInteger](x: T): T">bitnot[T: SomeInteger](x: T): T</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">bitslice
|
|
<li><a class="reference" href="#bitslice%2CT%2CSlice%5Bint%5D" title="bitslice[T: SomeInteger](v: var T; slice: Slice[int])">bitslice[T: SomeInteger](v: var T; slice: Slice[int])</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">bitsliced
|
|
<li><a class="reference" href="#bitsliced%2CT%2CSlice%5Bint%5D" title="bitsliced[T: SomeInteger](v: T; slice: Slice[int]): T">bitsliced[T: SomeInteger](v: T; slice: Slice[int]): T</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">clearBit
|
|
<li><a class="reference" href="#clearBit%2CT%2CBitsRange%5BT%3A%20SomeInteger%5D" title="clearBit[T: SomeInteger](v: var T; bit: BitsRange[T])">clearBit[T: SomeInteger](v: var T; bit: BitsRange[T])</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">clearMask
|
|
<li><a class="reference" href="#clearMask%2CT%2CT" title="clearMask[T: SomeInteger](v: var T; mask: T)">clearMask[T: SomeInteger](v: var T; mask: T)</a></li>
|
|
<li><a class="reference" href="#clearMask%2CT%2CSlice%5Bint%5D" title="clearMask[T: SomeInteger](v: var T; slice: Slice[int])">clearMask[T: SomeInteger](v: var T; slice: Slice[int])</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">clearMasked
|
|
<li><a class="reference" href="#clearMasked%2CT%2CT" title="clearMasked[T: SomeInteger](v, mask: T): T">clearMasked[T: SomeInteger](v, mask: T): T</a></li>
|
|
<li><a class="reference" href="#clearMasked%2CT%2CSlice%5Bint%5D" title="clearMasked[T: SomeInteger](v: T; slice: Slice[int]): T">clearMasked[T: SomeInteger](v: T; slice: Slice[int]): T</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">countLeadingZeroBits
|
|
<li><a class="reference" href="#countLeadingZeroBits%2CSomeInteger" title="countLeadingZeroBits(x: SomeInteger): int">countLeadingZeroBits(x: SomeInteger): int</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">countSetBits
|
|
<li><a class="reference" href="#countSetBits%2CSomeInteger" title="countSetBits(x: SomeInteger): int">countSetBits(x: SomeInteger): int</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">countTrailingZeroBits
|
|
<li><a class="reference" href="#countTrailingZeroBits%2CSomeInteger" title="countTrailingZeroBits(x: SomeInteger): int">countTrailingZeroBits(x: SomeInteger): int</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">fastLog2
|
|
<li><a class="reference" href="#fastLog2%2CSomeInteger" title="fastLog2(x: SomeInteger): int">fastLog2(x: SomeInteger): int</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">firstSetBit
|
|
<li><a class="reference" href="#firstSetBit%2CSomeInteger" title="firstSetBit(x: SomeInteger): int">firstSetBit(x: SomeInteger): int</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">flipBit
|
|
<li><a class="reference" href="#flipBit%2CT%2CBitsRange%5BT%3A%20SomeInteger%5D" title="flipBit[T: SomeInteger](v: var T; bit: BitsRange[T])">flipBit[T: SomeInteger](v: var T; bit: BitsRange[T])</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">flipMask
|
|
<li><a class="reference" href="#flipMask%2CT%2CT" title="flipMask[T: SomeInteger](v: var T; mask: T)">flipMask[T: SomeInteger](v: var T; mask: T)</a></li>
|
|
<li><a class="reference" href="#flipMask%2CT%2CSlice%5Bint%5D" title="flipMask[T: SomeInteger](v: var T; slice: Slice[int])">flipMask[T: SomeInteger](v: var T; slice: Slice[int])</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">flipMasked
|
|
<li><a class="reference" href="#flipMasked%2CT%2CT" title="flipMasked[T: SomeInteger](v, mask: T): T">flipMasked[T: SomeInteger](v, mask: T): T</a></li>
|
|
<li><a class="reference" href="#flipMasked%2CT%2CSlice%5Bint%5D" title="flipMasked[T: SomeInteger](v: T; slice: Slice[int]): T">flipMasked[T: SomeInteger](v: T; slice: Slice[int]): T</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">mask
|
|
<li><a class="reference" href="#mask%2CT%2CT" title="mask[T: SomeInteger](v: var T; mask: T)">mask[T: SomeInteger](v: var T; mask: T)</a></li>
|
|
<li><a class="reference" href="#mask%2CT%2CSlice%5Bint%5D" title="mask[T: SomeInteger](v: var T; slice: Slice[int])">mask[T: SomeInteger](v: var T; slice: Slice[int])</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">masked
|
|
<li><a class="reference" href="#masked%2CT%2CT" title="masked[T: SomeInteger](v, mask: T): T">masked[T: SomeInteger](v, mask: T): T</a></li>
|
|
<li><a class="reference" href="#masked%2CT%2CSlice%5Bint%5D" title="masked[T: SomeInteger](v: T; slice: Slice[int]): T">masked[T: SomeInteger](v: T; slice: Slice[int]): T</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">parityBits
|
|
<li><a class="reference" href="#parityBits%2CSomeInteger" title="parityBits(x: SomeInteger): int">parityBits(x: SomeInteger): int</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">popcount
|
|
<li><a class="reference" href="#popcount%2CSomeInteger" title="popcount(x: SomeInteger): int">popcount(x: SomeInteger): int</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">reverseBits
|
|
<li><a class="reference" href="#reverseBits%2CT" title="reverseBits[T: SomeUnsignedInt](x: T): T">reverseBits[T: SomeUnsignedInt](x: T): T</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">rotateLeftBits
|
|
<li><a class="reference" href="#rotateLeftBits%2CT%2Crange%5B%5D" title="rotateLeftBits[T: SomeUnsignedInt](value: T; shift: range[0 .. (sizeof(T) * 8)]): T">rotateLeftBits[T: SomeUnsignedInt](value: T; shift: range[0 .. (sizeof(T) * 8)]): T</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">rotateRightBits
|
|
<li><a class="reference" href="#rotateRightBits%2CT%2Crange%5B%5D" title="rotateRightBits[T: SomeUnsignedInt](value: T; shift: range[0 .. (sizeof(T) * 8)]): T">rotateRightBits[T: SomeUnsignedInt](value: T; shift: range[0 .. (sizeof(T) * 8)]): T</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">setBit
|
|
<li><a class="reference" href="#setBit%2CT%2CBitsRange%5BT%3A%20SomeInteger%5D" title="setBit[T: SomeInteger](v: var T; bit: BitsRange[T])">setBit[T: SomeInteger](v: var T; bit: BitsRange[T])</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">setMask
|
|
<li><a class="reference" href="#setMask%2CT%2CT" title="setMask[T: SomeInteger](v: var T; mask: T)">setMask[T: SomeInteger](v: var T; mask: T)</a></li>
|
|
<li><a class="reference" href="#setMask%2CT%2CSlice%5Bint%5D" title="setMask[T: SomeInteger](v: var T; slice: Slice[int])">setMask[T: SomeInteger](v: var T; slice: Slice[int])</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">setMasked
|
|
<li><a class="reference" href="#setMasked%2CT%2CT" title="setMasked[T: SomeInteger](v, mask: T): T">setMasked[T: SomeInteger](v, mask: T): T</a></li>
|
|
<li><a class="reference" href="#setMasked%2CT%2CSlice%5Bint%5D" title="setMasked[T: SomeInteger](v: T; slice: Slice[int]): T">setMasked[T: SomeInteger](v: T; slice: Slice[int]): T</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">testBit
|
|
<li><a class="reference" href="#testBit%2CT%2CBitsRange%5BT%3A%20SomeInteger%5D" title="testBit[T: SomeInteger](v: T; bit: BitsRange[T]): bool">testBit[T: SomeInteger](v: T; bit: BitsRange[T]): bool</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">toMask
|
|
<li><a class="reference" href="#toMask%2CSlice%5Bint%5D" title="toMask[T: SomeInteger](slice: Slice[int]): T">toMask[T: SomeInteger](slice: Slice[int]): T</a></li>
|
|
|
|
</ul>
|
|
|
|
</ul>
|
|
</details>
|
|
</li>
|
|
<li>
|
|
<details open>
|
|
<summary><a class="reference reference-toplevel" href="#17" id="67">Macros</a></summary>
|
|
<ul class="simple simple-toc-section">
|
|
<ul class="simple nested-toc-section">bitand
|
|
<li><a class="reference" href="#bitand.m%2CT%2CT%2Cvarargs%5BT%5D" title="bitand[T: SomeInteger](x, y: T; z: varargs[T]): T">bitand[T: SomeInteger](x, y: T; z: varargs[T]): T</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">bitor
|
|
<li><a class="reference" href="#bitor.m%2CT%2CT%2Cvarargs%5BT%5D" title="bitor[T: SomeInteger](x, y: T; z: varargs[T]): T">bitor[T: SomeInteger](x, y: T; z: varargs[T]): T</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">bitxor
|
|
<li><a class="reference" href="#bitxor.m%2CT%2CT%2Cvarargs%5BT%5D" title="bitxor[T: SomeInteger](x, y: T; z: varargs[T]): T">bitxor[T: SomeInteger](x, y: T; z: varargs[T]): T</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">clearBits
|
|
<li><a class="reference" href="#clearBits.m%2Ctyped%2Cvarargs%5Btyped%5D" title="clearBits(v: typed; bits: varargs[typed]): untyped">clearBits(v: typed; bits: varargs[typed]): untyped</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">flipBits
|
|
<li><a class="reference" href="#flipBits.m%2Ctyped%2Cvarargs%5Btyped%5D" title="flipBits(v: typed; bits: varargs[typed]): untyped">flipBits(v: typed; bits: varargs[typed]): untyped</a></li>
|
|
|
|
</ul>
|
|
<ul class="simple nested-toc-section">setBits
|
|
<li><a class="reference" href="#setBits.m%2Ctyped%2Cvarargs%5Btyped%5D" title="setBits(v: typed; bits: varargs[typed]): untyped">setBits(v: typed; bits: varargs[typed]): untyped</a></li>
|
|
|
|
</ul>
|
|
|
|
</ul>
|
|
</details>
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
<div class="nine columns" id="content">
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L1" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L1" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
<div id="tocRoot"></div>
|
|
|
|
<p class="module-desc"><p>This module implements a series of low level methods for bit manipulation.</p>
|
|
<p>By default, compiler intrinsics are used where possible to improve performance on supported compilers: <tt class="docutils literal"><span class="pre"><span class="Identifier">GCC</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Identifier">LLVM_GCC</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Identifier">CLANG</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Identifier">VCC</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Identifier">ICC</span></span></tt>.</p>
|
|
<p>The module will fallback to pure nim procs in case the backend is not supported. You can also use the flag <tt class="docutils literal"><span class="pre"><span class="Identifier">noIntrinsicsBitOpts</span></span></tt> to disable compiler intrinsics.</p>
|
|
<p>This module is also compatible with other backends: <tt class="docutils literal"><span class="pre"><span class="Identifier">JavaScript</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Identifier">NimScript</span></span></tt> as well as the <tt class="docutils literal"><span class="pre"><span class="Identifier">compiletime</span> <span class="Identifier">VM</span></span></tt>.</p>
|
|
<p>As a result of using optimized functions/intrinsics, some functions can return undefined results if the input is invalid. You can use the flag <tt class="docutils literal"><span class="pre"><span class="Identifier">noUndefinedBitOpts</span></span></tt> to force predictable behaviour for all input, causing a small performance hit.</p>
|
|
<p>At this time only <tt class="docutils literal"><span class="pre"><span class="Identifier">fastLog2</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Identifier">firstSetBit</span></span></tt>, <tt class="docutils literal"><span class="pre"><span class="Identifier">countLeadingZeroBits</span></span></tt> and <tt class="docutils literal"><span class="pre"><span class="Identifier">countTrailingZeroBits</span></span></tt> may return undefined and/or platform dependent values if given invalid input.</p>
|
|
</p>
|
|
<div class="section" id="6">
|
|
<h1><a class="toc-backref" href="#6">Imports</a></h1>
|
|
<dl class="item">
|
|
<a class="reference external" href="macros.html">macros</a>, <a class="reference external" href="since.html">since</a>, <a class="reference external" href="bitops_utils.html">bitops_utils</a>, <a class="reference external" href="countbits_impl.html">countbits_impl</a>
|
|
</dl>
|
|
</div>
|
|
<div class="section" id="7">
|
|
<h1><a class="toc-backref" href="#7">Types</a></h1>
|
|
<dl class="item">
|
|
<div id="BitsRange">
|
|
<dt><pre><a href="bitops.html#BitsRange"><span class="Identifier">BitsRange</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span> <span class="Other">=</span> <a href="system.html#range"><span class="Identifier">range</span></a><span class="Other">[</span><span class="DecNumber">0</span> <span class="Operator">..</span> <span class="Identifier">sizeof</span><span class="Other">(</span><span class="Identifier">T</span><span class="Other">)</span> <span class="Operator">*</span> <span class="DecNumber">8</span> <span class="Operator">-</span> <span class="DecNumber">1</span><span class="Other">]</span></pre></dt>
|
|
<dd>
|
|
|
|
A range with all bit positions for type <tt class="docutils literal"><span class="pre"><span class="Identifier">T</span></span></tt>.
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L63" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L63" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</dl>
|
|
</div>
|
|
<div class="section" id="12">
|
|
<h1><a class="toc-backref" href="#12">Procs</a></h1>
|
|
<dl class="item">
|
|
<div id="bitnot-procs-all">
|
|
<div id="bitnot,T">
|
|
<dt><pre><span class="Keyword">func</span> <a href="#bitnot%2CT"><span class="Identifier">bitnot</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">x</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">T</span> {.<span class="Identifier">magic</span><span class="Other">:</span> <span class="StringLit">"BitnotI"</span><span class="Other">,</span> <span><span class="Other pragmadots">...</span></span><span class="pragmawrap"><span class="Identifier">raises</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span> <span class="Identifier">tags</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span><span class="Other">,</span>
|
|
<span class="Identifier">forbids</span><span class="Other">:</span> <span class="Other">[</span><span class="Other">]</span></span>.}</pre></dt>
|
|
<dd>
|
|
|
|
Computes the <tt class="docutils literal"><span class="pre"><span class="Identifier">bitwise</span> <span class="Identifier">complement</span></span></tt> of the integer <tt class="docutils literal"><span class="pre"><span class="Identifier">x</span></span></tt>.
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L32" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L32" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="bitslice-procs-all">
|
|
<div id="bitslice,T,Slice[int]">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#bitslice%2CT%2CSlice%5Bint%5D"><span class="Identifier">bitslice</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">v</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">T</span><span class="Other">;</span> <span class="Identifier">slice</span><span class="Other">:</span> <a href="system.html#Slice"><span class="Identifier">Slice</span></a><span class="Other">[</span><a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">]</span><span class="Other">)</span> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
Mutates <tt class="docutils literal"><span class="pre"><span class="Identifier">v</span></span></tt> into an extracted (and shifted) slice of bits from <tt class="docutils literal"><span class="pre"><span class="Identifier">v</span></span></tt>.
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">var</span> <span class="Identifier">x</span> <span class="Operator">=</span> <span class="BinNumber">0b101110</span>
|
|
<span class="Identifier">x</span><span class="Operator">.</span><span class="Identifier">bitslice</span><span class="Punctuation">(</span><span class="DecNumber">2</span> <span class="Operator">..</span> <span class="DecNumber">4</span><span class="Punctuation">)</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">x</span> <span class="Operator">==</span> <span class="BinNumber">0b011</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L84" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L84" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="bitsliced-procs-all">
|
|
<div id="bitsliced,T,Slice[int]">
|
|
<dt><pre><span class="Keyword">func</span> <a href="#bitsliced%2CT%2CSlice%5Bint%5D"><span class="Identifier">bitsliced</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">v</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">;</span> <span class="Identifier">slice</span><span class="Other">:</span> <a href="system.html#Slice"><span class="Identifier">Slice</span></a><span class="Other">[</span><a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">T</span> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
Returns an extracted (and shifted) slice of bits from <tt class="docutils literal"><span class="pre"><span class="Identifier">v</span></span></tt>.
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Identifier">doAssert</span> <span class="BinNumber">0b10111</span><span class="Operator">.</span><span class="Identifier">bitsliced</span><span class="Punctuation">(</span><span class="DecNumber">2</span> <span class="Operator">..</span> <span class="DecNumber">4</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="BinNumber">0b101</span>
|
|
<span class="Identifier">doAssert</span> <span class="BinNumber">0b11100</span><span class="Operator">.</span><span class="Identifier">bitsliced</span><span class="Punctuation">(</span><span class="DecNumber">0</span> <span class="Operator">..</span> <span class="DecNumber">2</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="BinNumber">0b100</span>
|
|
<span class="Identifier">doAssert</span> <span class="BinNumber">0b11100</span><span class="Operator">.</span><span class="Identifier">bitsliced</span><span class="Punctuation">(</span><span class="DecNumber">0</span> <span class="Operator">..<</span> <span class="DecNumber">3</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="BinNumber">0b100</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L72" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L72" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="clearBit-procs-all">
|
|
<div id="clearBit,T,BitsRange[T: SomeInteger]">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#clearBit%2CT%2CBitsRange%5BT%3A%20SomeInteger%5D"><span class="Identifier">clearBit</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">v</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">T</span><span class="Other">;</span> <span class="Identifier">bit</span><span class="Other">:</span> <a href="bitops.html#BitsRange"><span class="Identifier">BitsRange</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">)</span> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
Mutates <tt class="docutils literal"><span class="pre"><span class="Identifier">v</span></span></tt>, with the bit at position <tt class="docutils literal"><span class="pre"><span class="Identifier">bit</span></span></tt> set to 0.
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">var</span> <span class="Identifier">v</span> <span class="Operator">=</span> <span class="BinNumber">0b0000_0011'</span><span class="Identifier">u8</span>
|
|
<span class="Identifier">v</span><span class="Operator">.</span><span class="Identifier">clearBit</span><span class="Punctuation">(</span><span class="DecNumber">1'</span><span class="Identifier">u8</span><span class="Punctuation">)</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">v</span> <span class="Operator">==</span> <span class="BinNumber">0b0000_0001'</span><span class="Identifier">u8</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L292" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L292" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="clearMask-procs-all">
|
|
<div id="clearMask,T,T">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#clearMask%2CT%2CT"><span class="Identifier">clearMask</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">v</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">T</span><span class="Other">;</span> <span class="Identifier">mask</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">)</span> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
<p>Mutates <tt class="docutils literal"><span class="pre"><span class="Identifier">v</span></span></tt>, with all the <tt class="docutils literal"><span class="pre"><span class="DecNumber">1</span></span></tt> bits from <tt class="docutils literal"><span class="pre"><span class="Identifier">mask</span></span></tt> set to 0.</p>
|
|
<p>Effectively maps to a <a class="reference external" href="#bitand.m,T,T,varargs[T]">bitand</a> operation with an <em>inverted mask</em>.</p>
|
|
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">var</span> <span class="Identifier">v</span> <span class="Operator">=</span> <span class="BinNumber">0b0000_0011'</span><span class="Identifier">u8</span>
|
|
<span class="Identifier">v</span><span class="Operator">.</span><span class="Identifier">clearMask</span><span class="Punctuation">(</span><span class="BinNumber">0b0000_1010'</span><span class="Identifier">u8</span><span class="Punctuation">)</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">v</span> <span class="Operator">==</span> <span class="BinNumber">0b0000_0001'</span><span class="Identifier">u8</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L217" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L217" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
<div id="clearMask,T,Slice[int]">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#clearMask%2CT%2CSlice%5Bint%5D"><span class="Identifier">clearMask</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">v</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">T</span><span class="Other">;</span> <span class="Identifier">slice</span><span class="Other">:</span> <a href="system.html#Slice"><span class="Identifier">Slice</span></a><span class="Other">[</span><a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">]</span><span class="Other">)</span> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
<p>Mutates <tt class="docutils literal"><span class="pre"><span class="Identifier">v</span></span></tt>, with all the <tt class="docutils literal"><span class="pre"><span class="DecNumber">1</span></span></tt> bits in the range of <tt class="docutils literal"><span class="pre"><span class="Identifier">slice</span></span></tt> set to 0.</p>
|
|
<p>Effectively maps to a <a class="reference external" href="#bitand.m,T,T,varargs[T]">bitand</a> operation with an <em>inverted mask</em>.</p>
|
|
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">var</span> <span class="Identifier">v</span> <span class="Operator">=</span> <span class="BinNumber">0b0000_0011'</span><span class="Identifier">u8</span>
|
|
<span class="Identifier">v</span><span class="Operator">.</span><span class="Identifier">clearMask</span><span class="Punctuation">(</span><span class="DecNumber">1</span> <span class="Operator">..</span> <span class="DecNumber">3</span><span class="Punctuation">)</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">v</span> <span class="Operator">==</span> <span class="BinNumber">0b0000_0001'</span><span class="Identifier">u8</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L229" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L229" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="clearMasked-procs-all">
|
|
<div id="clearMasked,T,T">
|
|
<dt><pre><span class="Keyword">func</span> <a href="#clearMasked%2CT%2CT"><span class="Identifier">clearMasked</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">v</span><span class="Other">,</span> <span class="Identifier">mask</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">T</span> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
<p>Returns <tt class="docutils literal"><span class="pre"><span class="Identifier">v</span></span></tt>, with all the <tt class="docutils literal"><span class="pre"><span class="DecNumber">1</span></span></tt> bits from <tt class="docutils literal"><span class="pre"><span class="Identifier">mask</span></span></tt> set to 0.</p>
|
|
<p>Effectively maps to a <a class="reference external" href="#bitand.m,T,T,varargs[T]">bitand</a> operation with an <em>inverted mask</em>.</p>
|
|
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">let</span> <span class="Identifier">v</span> <span class="Operator">=</span> <span class="BinNumber">0b0000_0011'</span><span class="Identifier">u8</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">v</span><span class="Operator">.</span><span class="Identifier">clearMasked</span><span class="Punctuation">(</span><span class="BinNumber">0b0000_1010'</span><span class="Identifier">u8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="BinNumber">0b0000_0001'</span><span class="Identifier">u8</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L195" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L195" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
<div id="clearMasked,T,Slice[int]">
|
|
<dt><pre><span class="Keyword">func</span> <a href="#clearMasked%2CT%2CSlice%5Bint%5D"><span class="Identifier">clearMasked</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">v</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">;</span> <span class="Identifier">slice</span><span class="Other">:</span> <a href="system.html#Slice"><span class="Identifier">Slice</span></a><span class="Other">[</span><a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">T</span> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
<p>Returns <tt class="docutils literal"><span class="pre"><span class="Identifier">v</span></span></tt>, with all the <tt class="docutils literal"><span class="pre"><span class="DecNumber">1</span></span></tt> bits in the range of <tt class="docutils literal"><span class="pre"><span class="Identifier">slice</span></span></tt> set to 0.</p>
|
|
<p>Effectively maps to a <a class="reference external" href="#bitand.m,T,T,varargs[T]">bitand</a> operation with an <em>inverted mask</em>.</p>
|
|
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">let</span> <span class="Identifier">v</span> <span class="Operator">=</span> <span class="BinNumber">0b0000_0011'</span><span class="Identifier">u8</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">v</span><span class="Operator">.</span><span class="Identifier">clearMasked</span><span class="Punctuation">(</span><span class="DecNumber">1</span> <span class="Operator">..</span> <span class="DecNumber">3</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="BinNumber">0b0000_0001'</span><span class="Identifier">u8</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L206" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L206" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="countLeadingZeroBits-procs-all">
|
|
<div id="countLeadingZeroBits,SomeInteger">
|
|
<dt><pre><span class="Keyword">func</span> <a href="#countLeadingZeroBits%2CSomeInteger"><span class="Identifier">countLeadingZeroBits</span></a><span class="Other">(</span><span class="Identifier">x</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
<p>Returns the number of leading zero bits in an integer. If <tt class="docutils literal"><span class="pre"><span class="Identifier">x</span></span></tt> is zero, when <tt class="docutils literal"><span class="pre"><span class="Identifier">noUndefinedBitOpts</span></span></tt> is set, the result is 0, otherwise the result is undefined.</p>
|
|
<p><strong>See also:</strong></p>
|
|
<ul class="simple"><li><a class="reference external" href="#countTrailingZeroBits,SomeInteger">countTrailingZeroBits proc</a></li>
|
|
</ul>
|
|
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Identifier">doAssert</span> <span class="Identifier">countLeadingZeroBits</span><span class="Punctuation">(</span><span class="BinNumber">0b0000_0001'</span><span class="Identifier">u8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">7</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">countLeadingZeroBits</span><span class="Punctuation">(</span><span class="BinNumber">0b0000_0010'</span><span class="Identifier">u8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">6</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">countLeadingZeroBits</span><span class="Punctuation">(</span><span class="BinNumber">0b0000_0100'</span><span class="Identifier">u8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">5</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">countLeadingZeroBits</span><span class="Punctuation">(</span><span class="BinNumber">0b0000_1000'</span><span class="Identifier">u8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">4</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">countLeadingZeroBits</span><span class="Punctuation">(</span><span class="BinNumber">0b0000_1111'</span><span class="Identifier">u8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">4</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L604" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L604" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="countSetBits-procs-all">
|
|
<div id="countSetBits,SomeInteger">
|
|
<dt><pre><span class="Keyword">func</span> <a href="#countSetBits%2CSomeInteger"><span class="Identifier">countSetBits</span></a><span class="Other">(</span><span class="Identifier">x</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
Counts the set bits in an integer (also called <span id="hamming-weight_1">Hamming weight</span>).
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Identifier">doAssert</span> <span class="Identifier">countSetBits</span><span class="Punctuation">(</span><span class="BinNumber">0b0000_0011'</span><span class="Identifier">u8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">countSetBits</span><span class="Punctuation">(</span><span class="BinNumber">0b1010_1010'</span><span class="Identifier">u8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">4</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L488" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L488" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="countTrailingZeroBits-procs-all">
|
|
<div id="countTrailingZeroBits,SomeInteger">
|
|
<dt><pre><span class="Keyword">func</span> <a href="#countTrailingZeroBits%2CSomeInteger"><span class="Identifier">countTrailingZeroBits</span></a><span class="Other">(</span><span class="Identifier">x</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
<p>Returns the number of trailing zeros in an integer. If <tt class="docutils literal"><span class="pre"><span class="Identifier">x</span></span></tt> is zero, when <tt class="docutils literal"><span class="pre"><span class="Identifier">noUndefinedBitOpts</span></span></tt> is set, the result is 0, otherwise the result is undefined.</p>
|
|
<p><strong>See also:</strong></p>
|
|
<ul class="simple"><li><a class="reference external" href="#countLeadingZeroBits,SomeInteger">countLeadingZeroBits proc</a></li>
|
|
</ul>
|
|
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Identifier">doAssert</span> <span class="Identifier">countTrailingZeroBits</span><span class="Punctuation">(</span><span class="BinNumber">0b0000_0001'</span><span class="Identifier">u8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">0</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">countTrailingZeroBits</span><span class="Punctuation">(</span><span class="BinNumber">0b0000_0010'</span><span class="Identifier">u8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">countTrailingZeroBits</span><span class="Punctuation">(</span><span class="BinNumber">0b0000_0100'</span><span class="Identifier">u8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">countTrailingZeroBits</span><span class="Punctuation">(</span><span class="BinNumber">0b0000_1000'</span><span class="Identifier">u8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">3</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">countTrailingZeroBits</span><span class="Punctuation">(</span><span class="BinNumber">0b0000_1111'</span><span class="Identifier">u8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">0</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L632" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L632" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="fastLog2-procs-all">
|
|
<div id="fastLog2,SomeInteger">
|
|
<dt><pre><span class="Keyword">func</span> <a href="#fastLog2%2CSomeInteger"><span class="Identifier">fastLog2</span></a><span class="Other">(</span><span class="Identifier">x</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
Quickly find the log base 2 of an integer. If <tt class="docutils literal"><span class="pre"><span class="Identifier">x</span></span></tt> is zero, when <tt class="docutils literal"><span class="pre"><span class="Identifier">noUndefinedBitOpts</span></span></tt> is set, the result is -1, otherwise the result is undefined.
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Identifier">doAssert</span> <span class="Identifier">fastLog2</span><span class="Punctuation">(</span><span class="BinNumber">0b0000_0001'</span><span class="Identifier">u8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">0</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">fastLog2</span><span class="Punctuation">(</span><span class="BinNumber">0b0000_0010'</span><span class="Identifier">u8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">fastLog2</span><span class="Punctuation">(</span><span class="BinNumber">0b0000_0100'</span><span class="Identifier">u8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">fastLog2</span><span class="Punctuation">(</span><span class="BinNumber">0b0000_1000'</span><span class="Identifier">u8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">3</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">fastLog2</span><span class="Punctuation">(</span><span class="BinNumber">0b0000_1111'</span><span class="Identifier">u8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">3</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L565" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L565" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="firstSetBit-procs-all">
|
|
<div id="firstSetBit,SomeInteger">
|
|
<dt><pre><span class="Keyword">func</span> <a href="#firstSetBit%2CSomeInteger"><span class="Identifier">firstSetBit</span></a><span class="Other">(</span><span class="Identifier">x</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
Returns the 1-based index of the least significant set bit of <tt class="docutils literal"><span class="pre"><span class="Identifier">x</span></span></tt>. If <tt class="docutils literal"><span class="pre"><span class="Identifier">x</span></span></tt> is zero, when <tt class="docutils literal"><span class="pre"><span class="Identifier">noUndefinedBitOpts</span></span></tt> is set, the result is 0, otherwise the result is undefined.
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Identifier">doAssert</span> <span class="Identifier">firstSetBit</span><span class="Punctuation">(</span><span class="BinNumber">0b0000_0001'</span><span class="Identifier">u8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">firstSetBit</span><span class="Punctuation">(</span><span class="BinNumber">0b0000_0010'</span><span class="Identifier">u8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">2</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">firstSetBit</span><span class="Punctuation">(</span><span class="BinNumber">0b0000_0100'</span><span class="Identifier">u8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">3</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">firstSetBit</span><span class="Punctuation">(</span><span class="BinNumber">0b0000_1000'</span><span class="Identifier">u8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">4</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">firstSetBit</span><span class="Punctuation">(</span><span class="BinNumber">0b0000_1111'</span><span class="Identifier">u8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L522" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L522" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="flipBit-procs-all">
|
|
<div id="flipBit,T,BitsRange[T: SomeInteger]">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#flipBit%2CT%2CBitsRange%5BT%3A%20SomeInteger%5D"><span class="Identifier">flipBit</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">v</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">T</span><span class="Other">;</span> <span class="Identifier">bit</span><span class="Other">:</span> <a href="bitops.html#BitsRange"><span class="Identifier">BitsRange</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">)</span> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
Mutates <tt class="docutils literal"><span class="pre"><span class="Identifier">v</span></span></tt>, with the bit at position <tt class="docutils literal"><span class="pre"><span class="Identifier">bit</span></span></tt> flipped.
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">var</span> <span class="Identifier">v</span> <span class="Operator">=</span> <span class="BinNumber">0b0000_0011'</span><span class="Identifier">u8</span>
|
|
<span class="Identifier">v</span><span class="Operator">.</span><span class="Identifier">flipBit</span><span class="Punctuation">(</span><span class="DecNumber">1'</span><span class="Identifier">u8</span><span class="Punctuation">)</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">v</span> <span class="Operator">==</span> <span class="BinNumber">0b0000_0001'</span><span class="Identifier">u8</span>
|
|
|
|
<span class="Identifier">v</span> <span class="Operator">=</span> <span class="BinNumber">0b0000_0011'</span><span class="Identifier">u8</span>
|
|
<span class="Identifier">v</span><span class="Operator">.</span><span class="Identifier">flipBit</span><span class="Punctuation">(</span><span class="DecNumber">2'</span><span class="Identifier">u8</span><span class="Punctuation">)</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">v</span> <span class="Operator">==</span> <span class="BinNumber">0b0000_0111'</span><span class="Identifier">u8</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L301" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L301" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="flipMask-procs-all">
|
|
<div id="flipMask,T,T">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#flipMask%2CT%2CT"><span class="Identifier">flipMask</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">v</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">T</span><span class="Other">;</span> <span class="Identifier">mask</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">)</span> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
<p>Mutates <tt class="docutils literal"><span class="pre"><span class="Identifier">v</span></span></tt>, with all the <tt class="docutils literal"><span class="pre"><span class="DecNumber">1</span></span></tt> bits from <tt class="docutils literal"><span class="pre"><span class="Identifier">mask</span></span></tt> flipped.</p>
|
|
<p>Effectively maps to a <a class="reference external" href="#bitxor.m,T,T,varargs[T]">bitxor</a> operation.</p>
|
|
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">var</span> <span class="Identifier">v</span> <span class="Operator">=</span> <span class="BinNumber">0b0000_0011'</span><span class="Identifier">u8</span>
|
|
<span class="Identifier">v</span><span class="Operator">.</span><span class="Identifier">flipMask</span><span class="Punctuation">(</span><span class="BinNumber">0b0000_1010'</span><span class="Identifier">u8</span><span class="Punctuation">)</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">v</span> <span class="Operator">==</span> <span class="BinNumber">0b0000_1001'</span><span class="Identifier">u8</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L261" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L261" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
<div id="flipMask,T,Slice[int]">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#flipMask%2CT%2CSlice%5Bint%5D"><span class="Identifier">flipMask</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">v</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">T</span><span class="Other">;</span> <span class="Identifier">slice</span><span class="Other">:</span> <a href="system.html#Slice"><span class="Identifier">Slice</span></a><span class="Other">[</span><a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">]</span><span class="Other">)</span> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
<p>Mutates <tt class="docutils literal"><span class="pre"><span class="Identifier">v</span></span></tt>, with all the <tt class="docutils literal"><span class="pre"><span class="DecNumber">1</span></span></tt> bits in the range of <tt class="docutils literal"><span class="pre"><span class="Identifier">slice</span></span></tt> flipped.</p>
|
|
<p>Effectively maps to a <a class="reference external" href="#bitxor.m,T,T,varargs[T]">bitxor</a> operation.</p>
|
|
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">var</span> <span class="Identifier">v</span> <span class="Operator">=</span> <span class="BinNumber">0b0000_0011'</span><span class="Identifier">u8</span>
|
|
<span class="Identifier">v</span><span class="Operator">.</span><span class="Identifier">flipMask</span><span class="Punctuation">(</span><span class="DecNumber">1</span> <span class="Operator">..</span> <span class="DecNumber">3</span><span class="Punctuation">)</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">v</span> <span class="Operator">==</span> <span class="BinNumber">0b0000_1101'</span><span class="Identifier">u8</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L272" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L272" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="flipMasked-procs-all">
|
|
<div id="flipMasked,T,T">
|
|
<dt><pre><span class="Keyword">func</span> <a href="#flipMasked%2CT%2CT"><span class="Identifier">flipMasked</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">v</span><span class="Other">,</span> <span class="Identifier">mask</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">T</span> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
<p>Returns <tt class="docutils literal"><span class="pre"><span class="Identifier">v</span></span></tt>, with all the <tt class="docutils literal"><span class="pre"><span class="DecNumber">1</span></span></tt> bits from <tt class="docutils literal"><span class="pre"><span class="Identifier">mask</span></span></tt> flipped.</p>
|
|
<p>Effectively maps to a <a class="reference external" href="#bitxor.m,T,T,varargs[T]">bitxor</a> operation.</p>
|
|
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">let</span> <span class="Identifier">v</span> <span class="Operator">=</span> <span class="BinNumber">0b0000_0011'</span><span class="Identifier">u8</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">v</span><span class="Operator">.</span><span class="Identifier">flipMasked</span><span class="Punctuation">(</span><span class="BinNumber">0b0000_1010'</span><span class="Identifier">u8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="BinNumber">0b0000_1001'</span><span class="Identifier">u8</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L241" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L241" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
<div id="flipMasked,T,Slice[int]">
|
|
<dt><pre><span class="Keyword">func</span> <a href="#flipMasked%2CT%2CSlice%5Bint%5D"><span class="Identifier">flipMasked</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">v</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">;</span> <span class="Identifier">slice</span><span class="Other">:</span> <a href="system.html#Slice"><span class="Identifier">Slice</span></a><span class="Other">[</span><a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">T</span> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
<p>Returns <tt class="docutils literal"><span class="pre"><span class="Identifier">v</span></span></tt>, with all the <tt class="docutils literal"><span class="pre"><span class="DecNumber">1</span></span></tt> bits in the range of <tt class="docutils literal"><span class="pre"><span class="Identifier">slice</span></span></tt> flipped.</p>
|
|
<p>Effectively maps to a <a class="reference external" href="#bitxor.m,T,T,varargs[T]">bitxor</a> operation.</p>
|
|
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">let</span> <span class="Identifier">v</span> <span class="Operator">=</span> <span class="BinNumber">0b0000_0011'</span><span class="Identifier">u8</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">v</span><span class="Operator">.</span><span class="Identifier">flipMasked</span><span class="Punctuation">(</span><span class="DecNumber">1</span> <span class="Operator">..</span> <span class="DecNumber">3</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="BinNumber">0b0000_1101'</span><span class="Identifier">u8</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L251" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L251" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="mask-procs-all">
|
|
<div id="mask,T,T">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#mask%2CT%2CT"><span class="Identifier">mask</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">v</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">T</span><span class="Other">;</span> <span class="Identifier">mask</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">)</span> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
<p>Mutates <tt class="docutils literal"><span class="pre"><span class="Identifier">v</span></span></tt>, with only the <tt class="docutils literal"><span class="pre"><span class="DecNumber">1</span></span></tt> bits from <tt class="docutils literal"><span class="pre"><span class="Identifier">mask</span></span></tt> matching those of <tt class="docutils literal"><span class="pre"><span class="Identifier">v</span></span></tt> set to 1.</p>
|
|
<p>Effectively maps to a <a class="reference external" href="#bitand.m,T,T,varargs[T]">bitand</a> operation.</p>
|
|
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">var</span> <span class="Identifier">v</span> <span class="Operator">=</span> <span class="BinNumber">0b0000_0011'</span><span class="Identifier">u8</span>
|
|
<span class="Identifier">v</span><span class="Operator">.</span><span class="Identifier">mask</span><span class="Punctuation">(</span><span class="BinNumber">0b0000_1010'</span><span class="Identifier">u8</span><span class="Punctuation">)</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">v</span> <span class="Operator">==</span> <span class="BinNumber">0b0000_0010'</span><span class="Identifier">u8</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L129" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L129" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
<div id="mask,T,Slice[int]">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#mask%2CT%2CSlice%5Bint%5D"><span class="Identifier">mask</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">v</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">T</span><span class="Other">;</span> <span class="Identifier">slice</span><span class="Other">:</span> <a href="system.html#Slice"><span class="Identifier">Slice</span></a><span class="Other">[</span><a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">]</span><span class="Other">)</span> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
<p>Mutates <tt class="docutils literal"><span class="pre"><span class="Identifier">v</span></span></tt>, with only the <tt class="docutils literal"><span class="pre"><span class="DecNumber">1</span></span></tt> bits in the range of <tt class="docutils literal"><span class="pre"><span class="Identifier">slice</span></span></tt> matching those of <tt class="docutils literal"><span class="pre"><span class="Identifier">v</span></span></tt> set to 1.</p>
|
|
<p>Effectively maps to a <a class="reference external" href="#bitand.m,T,T,varargs[T]">bitand</a> operation.</p>
|
|
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">var</span> <span class="Identifier">v</span> <span class="Operator">=</span> <span class="BinNumber">0b0000_1011'</span><span class="Identifier">u8</span>
|
|
<span class="Identifier">v</span><span class="Operator">.</span><span class="Identifier">mask</span><span class="Punctuation">(</span><span class="DecNumber">1</span> <span class="Operator">..</span> <span class="DecNumber">3</span><span class="Punctuation">)</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">v</span> <span class="Operator">==</span> <span class="BinNumber">0b0000_1010'</span><span class="Identifier">u8</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L141" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L141" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="masked-procs-all">
|
|
<div id="masked,T,T">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#masked%2CT%2CT"><span class="Identifier">masked</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">v</span><span class="Other">,</span> <span class="Identifier">mask</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">T</span> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
<p>Returns <tt class="docutils literal"><span class="pre"><span class="Identifier">v</span></span></tt>, with only the <tt class="docutils literal"><span class="pre"><span class="DecNumber">1</span></span></tt> bits from <tt class="docutils literal"><span class="pre"><span class="Identifier">mask</span></span></tt> matching those of <tt class="docutils literal"><span class="pre"><span class="Identifier">v</span></span></tt> set to 1.</p>
|
|
<p>Effectively maps to a <a class="reference external" href="#bitand.m,T,T,varargs[T]">bitand</a> operation.</p>
|
|
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">let</span> <span class="Identifier">v</span> <span class="Operator">=</span> <span class="BinNumber">0b0000_0011'</span><span class="Identifier">u8</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">v</span><span class="Operator">.</span><span class="Identifier">masked</span><span class="Punctuation">(</span><span class="BinNumber">0b0000_1010'</span><span class="Identifier">u8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="BinNumber">0b0000_0010'</span><span class="Identifier">u8</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L107" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L107" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
<div id="masked,T,Slice[int]">
|
|
<dt><pre><span class="Keyword">func</span> <a href="#masked%2CT%2CSlice%5Bint%5D"><span class="Identifier">masked</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">v</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">;</span> <span class="Identifier">slice</span><span class="Other">:</span> <a href="system.html#Slice"><span class="Identifier">Slice</span></a><span class="Other">[</span><a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">T</span> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
<p>Returns <tt class="docutils literal"><span class="pre"><span class="Identifier">v</span></span></tt>, with only the <tt class="docutils literal"><span class="pre"><span class="DecNumber">1</span></span></tt> bits in the range of <tt class="docutils literal"><span class="pre"><span class="Identifier">slice</span></span></tt> matching those of <tt class="docutils literal"><span class="pre"><span class="Identifier">v</span></span></tt> set to 1.</p>
|
|
<p>Effectively maps to a <a class="reference external" href="#bitand.m,T,T,varargs[T]">bitand</a> operation.</p>
|
|
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">let</span> <span class="Identifier">v</span> <span class="Operator">=</span> <span class="BinNumber">0b0000_1011'</span><span class="Identifier">u8</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">v</span><span class="Operator">.</span><span class="Identifier">masked</span><span class="Punctuation">(</span><span class="DecNumber">1</span> <span class="Operator">..</span> <span class="DecNumber">3</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="BinNumber">0b0000_1010'</span><span class="Identifier">u8</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L118" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L118" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="parityBits-procs-all">
|
|
<div id="parityBits,SomeInteger">
|
|
<dt><pre><span class="Keyword">func</span> <a href="#parityBits%2CSomeInteger"><span class="Identifier">parityBits</span></a><span class="Other">(</span><span class="Identifier">x</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
Calculate the bit parity in an integer. If the number of 1-bits is odd, the parity is 1, otherwise 0.
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Identifier">doAssert</span> <span class="Identifier">parityBits</span><span class="Punctuation">(</span><span class="BinNumber">0b0000_0000'</span><span class="Identifier">u8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">0</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">parityBits</span><span class="Punctuation">(</span><span class="BinNumber">0b0101_0001'</span><span class="Identifier">u8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">parityBits</span><span class="Punctuation">(</span><span class="BinNumber">0b0110_1001'</span><span class="Identifier">u8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">0</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">parityBits</span><span class="Punctuation">(</span><span class="BinNumber">0b0111_1111'</span><span class="Identifier">u8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="DecNumber">1</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L500" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L500" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="popcount-procs-all">
|
|
<div id="popcount,SomeInteger">
|
|
<dt><pre><span class="Keyword">func</span> <a href="#popcount%2CSomeInteger"><span class="Identifier">popcount</span></a><span class="Other">(</span><span class="Identifier">x</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a><span class="Other">)</span><span class="Other">:</span> <a href="system.html#int"><span class="Identifier">int</span></a> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
Alias for <a class="reference external" href="#countSetBits,SomeInteger">countSetBits</a> (Hamming weight).
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L496" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L496" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="reverseBits-procs-all">
|
|
<div id="reverseBits,T">
|
|
<dt><pre><span class="Keyword">func</span> <a href="#reverseBits%2CT"><span class="Identifier">reverseBits</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#SomeUnsignedInt"><span class="Identifier">SomeUnsignedInt</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">x</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">T</span></pre></dt>
|
|
<dd>
|
|
|
|
Return the bit reversal of x.
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Identifier">doAssert</span> <span class="Identifier">reverseBits</span><span class="Punctuation">(</span><span class="BinNumber">0b10100100'</span><span class="Identifier">u8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="BinNumber">0b00100101'</span><span class="Identifier">u8</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">reverseBits</span><span class="Punctuation">(</span><span class="HexNumber">0xdd'</span><span class="Identifier">u8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="HexNumber">0xbb'</span><span class="Identifier">u8</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">reverseBits</span><span class="Punctuation">(</span><span class="HexNumber">0xddbb'</span><span class="Identifier">u16</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="HexNumber">0xddbb'</span><span class="Identifier">u16</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">reverseBits</span><span class="Punctuation">(</span><span class="HexNumber">0xdeadbeef'</span><span class="Identifier">u32</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="HexNumber">0xf77db57b'</span><span class="Identifier">u32</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L848" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L848" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="rotateLeftBits-procs-all">
|
|
<div id="rotateLeftBits,T,range[]">
|
|
<dt><pre><span class="Keyword">func</span> <a href="#rotateLeftBits%2CT%2Crange%5B%5D"><span class="Identifier">rotateLeftBits</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#SomeUnsignedInt"><span class="Identifier">SomeUnsignedInt</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">value</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">;</span>
|
|
<span class="Identifier">shift</span><span class="Other">:</span> <a href="system.html#range"><span class="Identifier">range</span></a><span class="Other">[</span><span class="DecNumber">0</span> <span class="Operator">..</span> <span class="Other">(</span><span class="Identifier">sizeof</span><span class="Other">(</span><span class="Identifier">T</span><span class="Other">)</span> <span class="Operator">*</span> <span class="DecNumber">8</span><span class="Other">)</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">T</span> {.
|
|
<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
Left-rotate bits in a <tt class="docutils literal"><span class="pre"><span class="Identifier">value</span></span></tt>.
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Identifier">doAssert</span> <span class="Identifier">rotateLeftBits</span><span class="Punctuation">(</span><span class="BinNumber">0b0110_1001'</span><span class="Identifier">u8</span><span class="Punctuation">,</span> <span class="DecNumber">4</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="BinNumber">0b1001_0110'</span><span class="Identifier">u8</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">rotateLeftBits</span><span class="Punctuation">(</span><span class="BinNumber">0b00111100_11000011'</span><span class="Identifier">u16</span><span class="Punctuation">,</span> <span class="DecNumber">8</span><span class="Punctuation">)</span> <span class="Operator">==</span>
|
|
<span class="BinNumber">0b11000011_00111100'</span><span class="Identifier">u16</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">rotateLeftBits</span><span class="Punctuation">(</span><span class="BinNumber">0b0000111111110000_1111000000001111'</span><span class="Identifier">u32</span><span class="Punctuation">,</span> <span class="DecNumber">16</span><span class="Punctuation">)</span> <span class="Operator">==</span>
|
|
<span class="BinNumber">0b1111000000001111_0000111111110000'</span><span class="Identifier">u32</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">rotateLeftBits</span><span class="Punctuation">(</span><span class="BinNumber">0b00000000111111111111111100000000_11111111000000000000000011111111'</span><span class="Identifier">u64</span><span class="Punctuation">,</span> <span class="DecNumber">32</span><span class="Punctuation">)</span> <span class="Operator">==</span>
|
|
<span class="BinNumber">0b11111111000000000000000011111111_00000000111111111111111100000000'</span><span class="Identifier">u64</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L785" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L785" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="rotateRightBits-procs-all">
|
|
<div id="rotateRightBits,T,range[]">
|
|
<dt><pre><span class="Keyword">func</span> <a href="#rotateRightBits%2CT%2Crange%5B%5D"><span class="Identifier">rotateRightBits</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#SomeUnsignedInt"><span class="Identifier">SomeUnsignedInt</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">value</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">;</span>
|
|
<span class="Identifier">shift</span><span class="Other">:</span> <a href="system.html#range"><span class="Identifier">range</span></a><span class="Other">[</span><span class="DecNumber">0</span> <span class="Operator">..</span> <span class="Other">(</span><span class="Identifier">sizeof</span><span class="Other">(</span><span class="Identifier">T</span><span class="Other">)</span> <span class="Operator">*</span> <span class="DecNumber">8</span><span class="Other">)</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">T</span> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
Right-rotate bits in a <tt class="docutils literal"><span class="pre"><span class="Identifier">value</span></span></tt>.
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Identifier">doAssert</span> <span class="Identifier">rotateRightBits</span><span class="Punctuation">(</span><span class="BinNumber">0b0110_1001'</span><span class="Identifier">u8</span><span class="Punctuation">,</span> <span class="DecNumber">4</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="BinNumber">0b1001_0110'</span><span class="Identifier">u8</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">rotateRightBits</span><span class="Punctuation">(</span><span class="BinNumber">0b00111100_11000011'</span><span class="Identifier">u16</span><span class="Punctuation">,</span> <span class="DecNumber">8</span><span class="Punctuation">)</span> <span class="Operator">==</span>
|
|
<span class="BinNumber">0b11000011_00111100'</span><span class="Identifier">u16</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">rotateRightBits</span><span class="Punctuation">(</span><span class="BinNumber">0b0000111111110000_1111000000001111'</span><span class="Identifier">u32</span><span class="Punctuation">,</span> <span class="DecNumber">16</span><span class="Punctuation">)</span> <span class="Operator">==</span>
|
|
<span class="BinNumber">0b1111000000001111_0000111111110000'</span><span class="Identifier">u32</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">rotateRightBits</span><span class="Punctuation">(</span><span class="BinNumber">0b00000000111111111111111100000000_11111111000000000000000011111111'</span><span class="Identifier">u64</span><span class="Punctuation">,</span> <span class="DecNumber">32</span><span class="Punctuation">)</span> <span class="Operator">==</span>
|
|
<span class="BinNumber">0b11111111000000000000000011111111_00000000111111111111111100000000'</span><span class="Identifier">u64</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L813" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L813" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="setBit-procs-all">
|
|
<div id="setBit,T,BitsRange[T: SomeInteger]">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#setBit%2CT%2CBitsRange%5BT%3A%20SomeInteger%5D"><span class="Identifier">setBit</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">v</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">T</span><span class="Other">;</span> <span class="Identifier">bit</span><span class="Other">:</span> <a href="bitops.html#BitsRange"><span class="Identifier">BitsRange</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">)</span> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
Mutates <tt class="docutils literal"><span class="pre"><span class="Identifier">v</span></span></tt>, with the bit at position <tt class="docutils literal"><span class="pre"><span class="Identifier">bit</span></span></tt> set to 1.
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">var</span> <span class="Identifier">v</span> <span class="Operator">=</span> <span class="BinNumber">0b0000_0011'</span><span class="Identifier">u8</span>
|
|
<span class="Identifier">v</span><span class="Operator">.</span><span class="Identifier">setBit</span><span class="Punctuation">(</span><span class="DecNumber">5'</span><span class="Identifier">u8</span><span class="Punctuation">)</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">v</span> <span class="Operator">==</span> <span class="BinNumber">0b0010_0011'</span><span class="Identifier">u8</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L283" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L283" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="setMask-procs-all">
|
|
<div id="setMask,T,T">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#setMask%2CT%2CT"><span class="Identifier">setMask</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">v</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">T</span><span class="Other">;</span> <span class="Identifier">mask</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">)</span> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
<p>Mutates <tt class="docutils literal"><span class="pre"><span class="Identifier">v</span></span></tt>, with all the <tt class="docutils literal"><span class="pre"><span class="DecNumber">1</span></span></tt> bits from <tt class="docutils literal"><span class="pre"><span class="Identifier">mask</span></span></tt> set to 1.</p>
|
|
<p>Effectively maps to a <a class="reference external" href="#bitor.m,T,T,varargs[T]">bitor</a> operation.</p>
|
|
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">var</span> <span class="Identifier">v</span> <span class="Operator">=</span> <span class="BinNumber">0b0000_0011'</span><span class="Identifier">u8</span>
|
|
<span class="Identifier">v</span><span class="Operator">.</span><span class="Identifier">setMask</span><span class="Punctuation">(</span><span class="BinNumber">0b0000_1010'</span><span class="Identifier">u8</span><span class="Punctuation">)</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">v</span> <span class="Operator">==</span> <span class="BinNumber">0b0000_1011'</span><span class="Identifier">u8</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L173" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L173" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
<div id="setMask,T,Slice[int]">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#setMask%2CT%2CSlice%5Bint%5D"><span class="Identifier">setMask</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">v</span><span class="Other">:</span> <span class="Keyword">var</span> <span class="Identifier">T</span><span class="Other">;</span> <span class="Identifier">slice</span><span class="Other">:</span> <a href="system.html#Slice"><span class="Identifier">Slice</span></a><span class="Other">[</span><a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">]</span><span class="Other">)</span> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
<p>Mutates <tt class="docutils literal"><span class="pre"><span class="Identifier">v</span></span></tt>, with all the <tt class="docutils literal"><span class="pre"><span class="DecNumber">1</span></span></tt> bits in the range of <tt class="docutils literal"><span class="pre"><span class="Identifier">slice</span></span></tt> set to 1.</p>
|
|
<p>Effectively maps to a <a class="reference external" href="#bitor.m,T,T,varargs[T]">bitor</a> operation.</p>
|
|
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">var</span> <span class="Identifier">v</span> <span class="Operator">=</span> <span class="BinNumber">0b0000_0011'</span><span class="Identifier">u8</span>
|
|
<span class="Identifier">v</span><span class="Operator">.</span><span class="Identifier">setMask</span><span class="Punctuation">(</span><span class="DecNumber">2</span> <span class="Operator">..</span> <span class="DecNumber">3</span><span class="Punctuation">)</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">v</span> <span class="Operator">==</span> <span class="BinNumber">0b0000_1111'</span><span class="Identifier">u8</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L184" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L184" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="setMasked-procs-all">
|
|
<div id="setMasked,T,T">
|
|
<dt><pre><span class="Keyword">func</span> <a href="#setMasked%2CT%2CT"><span class="Identifier">setMasked</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">v</span><span class="Other">,</span> <span class="Identifier">mask</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">T</span> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
<p>Returns <tt class="docutils literal"><span class="pre"><span class="Identifier">v</span></span></tt>, with all the <tt class="docutils literal"><span class="pre"><span class="DecNumber">1</span></span></tt> bits from <tt class="docutils literal"><span class="pre"><span class="Identifier">mask</span></span></tt> set to 1.</p>
|
|
<p>Effectively maps to a <a class="reference external" href="#bitor.m,T,T,varargs[T]">bitor</a> operation.</p>
|
|
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">let</span> <span class="Identifier">v</span> <span class="Operator">=</span> <span class="BinNumber">0b0000_0011'</span><span class="Identifier">u8</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">v</span><span class="Operator">.</span><span class="Identifier">setMasked</span><span class="Punctuation">(</span><span class="BinNumber">0b0000_1010'</span><span class="Identifier">u8</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="BinNumber">0b0000_1011'</span><span class="Identifier">u8</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L153" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L153" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
<div id="setMasked,T,Slice[int]">
|
|
<dt><pre><span class="Keyword">func</span> <a href="#setMasked%2CT%2CSlice%5Bint%5D"><span class="Identifier">setMasked</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">v</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">;</span> <span class="Identifier">slice</span><span class="Other">:</span> <a href="system.html#Slice"><span class="Identifier">Slice</span></a><span class="Other">[</span><a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">T</span> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
<p>Returns <tt class="docutils literal"><span class="pre"><span class="Identifier">v</span></span></tt>, with all the <tt class="docutils literal"><span class="pre"><span class="DecNumber">1</span></span></tt> bits in the range of <tt class="docutils literal"><span class="pre"><span class="Identifier">slice</span></span></tt> set to 1.</p>
|
|
<p>Effectively maps to a <a class="reference external" href="#bitor.m,T,T,varargs[T]">bitor</a> operation.</p>
|
|
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">let</span> <span class="Identifier">v</span> <span class="Operator">=</span> <span class="BinNumber">0b0000_0011'</span><span class="Identifier">u8</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">v</span><span class="Operator">.</span><span class="Identifier">setMasked</span><span class="Punctuation">(</span><span class="DecNumber">2</span> <span class="Operator">..</span> <span class="DecNumber">3</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="BinNumber">0b0000_1111'</span><span class="Identifier">u8</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L163" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L163" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="testBit-procs-all">
|
|
<div id="testBit,T,BitsRange[T: SomeInteger]">
|
|
<dt><pre><span class="Keyword">proc</span> <a href="#testBit%2CT%2CBitsRange%5BT%3A%20SomeInteger%5D"><span class="Identifier">testBit</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">v</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">;</span> <span class="Identifier">bit</span><span class="Other">:</span> <a href="bitops.html#BitsRange"><span class="Identifier">BitsRange</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#bool"><span class="Identifier">bool</span></a> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
Returns true if the bit in <tt class="docutils literal"><span class="pre"><span class="Identifier">v</span></span></tt> at positions <tt class="docutils literal"><span class="pre"><span class="Identifier">bit</span></span></tt> is set to 1.
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">let</span> <span class="Identifier">v</span> <span class="Operator">=</span> <span class="BinNumber">0b0000_1111'</span><span class="Identifier">u8</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">v</span><span class="Operator">.</span><span class="Identifier">testBit</span><span class="Punctuation">(</span><span class="DecNumber">0</span><span class="Punctuation">)</span>
|
|
<span class="Identifier">doAssert</span> <span class="Keyword">not</span> <span class="Identifier">v</span><span class="Operator">.</span><span class="Identifier">testBit</span><span class="Punctuation">(</span><span class="DecNumber">7</span><span class="Punctuation">)</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L351" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L351" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="toMask-procs-all">
|
|
<div id="toMask,Slice[int]">
|
|
<dt><pre><span class="Keyword">func</span> <a href="#toMask%2CSlice%5Bint%5D"><span class="Identifier">toMask</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">slice</span><span class="Other">:</span> <a href="system.html#Slice"><span class="Identifier">Slice</span></a><span class="Other">[</span><a href="system.html#int"><span class="Identifier">int</span></a><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">T</span> {.<span class="Identifier">inline</span>.}</pre></dt>
|
|
<dd>
|
|
|
|
Creates a bitmask based on a slice of bits.
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Identifier">doAssert</span> <span class="Identifier">toMask</span><span class="Punctuation">[</span><span class="Identifier">int32</span><span class="Punctuation">]</span><span class="Punctuation">(</span><span class="DecNumber">1</span> <span class="Operator">..</span> <span class="DecNumber">3</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="BinNumber">0b1110'i32</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">toMask</span><span class="Punctuation">[</span><span class="Identifier">int32</span><span class="Punctuation">]</span><span class="Punctuation">(</span><span class="DecNumber">0</span> <span class="Operator">..</span> <span class="DecNumber">3</span><span class="Punctuation">)</span> <span class="Operator">==</span> <span class="BinNumber">0b1111'i32</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L96" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L96" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</dl>
|
|
</div>
|
|
<div class="section" id="17">
|
|
<h1><a class="toc-backref" href="#17">Macros</a></h1>
|
|
<dl class="item">
|
|
<div id="bitand-macros-all">
|
|
<div id="bitand.m,T,T,varargs[T]">
|
|
<dt><pre><span class="Keyword">macro</span> <a href="#bitand.m%2CT%2CT%2Cvarargs%5BT%5D"><span class="Identifier">bitand</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">x</span><span class="Other">,</span> <span class="Identifier">y</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">;</span> <span class="Identifier">z</span><span class="Other">:</span> <a href="system.html#varargs"><span class="Identifier">varargs</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">T</span></pre></dt>
|
|
<dd>
|
|
|
|
Computes the <tt class="docutils literal"><span class="pre"><span class="Identifier">bitwise</span> <span class="Keyword">and</span></span></tt> of all arguments collectively.
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L41" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L41" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="bitor-macros-all">
|
|
<div id="bitor.m,T,T,varargs[T]">
|
|
<dt><pre><span class="Keyword">macro</span> <a href="#bitor.m%2CT%2CT%2Cvarargs%5BT%5D"><span class="Identifier">bitor</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">x</span><span class="Other">,</span> <span class="Identifier">y</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">;</span> <span class="Identifier">z</span><span class="Other">:</span> <a href="system.html#varargs"><span class="Identifier">varargs</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">T</span></pre></dt>
|
|
<dd>
|
|
|
|
Computes the <tt class="docutils literal"><span class="pre"><span class="Identifier">bitwise</span> <span class="Keyword">or</span></span></tt> of all arguments collectively.
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L48" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L48" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="bitxor-macros-all">
|
|
<div id="bitxor.m,T,T,varargs[T]">
|
|
<dt><pre><span class="Keyword">macro</span> <a href="#bitxor.m%2CT%2CT%2Cvarargs%5BT%5D"><span class="Identifier">bitxor</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">:</span> <a href="system.html#SomeInteger"><span class="Identifier">SomeInteger</span></a><span class="Other">]</span><span class="Other">(</span><span class="Identifier">x</span><span class="Other">,</span> <span class="Identifier">y</span><span class="Other">:</span> <span class="Identifier">T</span><span class="Other">;</span> <span class="Identifier">z</span><span class="Other">:</span> <a href="system.html#varargs"><span class="Identifier">varargs</span></a><span class="Other">[</span><span class="Identifier">T</span><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <span class="Identifier">T</span></pre></dt>
|
|
<dd>
|
|
|
|
Computes the <tt class="docutils literal"><span class="pre"><span class="Identifier">bitwise</span> <span class="Keyword">xor</span></span></tt> of all arguments collectively.
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L55" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L55" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="clearBits-macros-all">
|
|
<div id="clearBits.m,typed,varargs[typed]">
|
|
<dt><pre><span class="Keyword">macro</span> <a href="#clearBits.m%2Ctyped%2Cvarargs%5Btyped%5D"><span class="Identifier">clearBits</span></a><span class="Other">(</span><span class="Identifier">v</span><span class="Other">:</span> <a href="system.html#typed"><span class="Identifier">typed</span></a><span class="Other">;</span> <span class="Identifier">bits</span><span class="Other">:</span> <a href="system.html#varargs"><span class="Identifier">varargs</span></a><span class="Other">[</span><a href="system.html#typed"><span class="Identifier">typed</span></a><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#untyped"><span class="Identifier">untyped</span></a></pre></dt>
|
|
<dd>
|
|
|
|
Mutates <tt class="docutils literal"><span class="pre"><span class="Identifier">v</span></span></tt>, with the bits at positions <tt class="docutils literal"><span class="pre"><span class="Identifier">bits</span></span></tt> set to 0.
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">var</span> <span class="Identifier">v</span> <span class="Operator">=</span> <span class="BinNumber">0b1111_1111'</span><span class="Identifier">u8</span>
|
|
<span class="Identifier">v</span><span class="Operator">.</span><span class="Identifier">clearBits</span><span class="Punctuation">(</span><span class="DecNumber">1</span><span class="Punctuation">,</span> <span class="DecNumber">3</span><span class="Punctuation">,</span> <span class="DecNumber">5</span><span class="Punctuation">,</span> <span class="DecNumber">7</span><span class="Punctuation">)</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">v</span> <span class="Operator">==</span> <span class="BinNumber">0b0101_0101'</span><span class="Identifier">u8</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L326" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L326" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="flipBits-macros-all">
|
|
<div id="flipBits.m,typed,varargs[typed]">
|
|
<dt><pre><span class="Keyword">macro</span> <a href="#flipBits.m%2Ctyped%2Cvarargs%5Btyped%5D"><span class="Identifier">flipBits</span></a><span class="Other">(</span><span class="Identifier">v</span><span class="Other">:</span> <a href="system.html#typed"><span class="Identifier">typed</span></a><span class="Other">;</span> <span class="Identifier">bits</span><span class="Other">:</span> <a href="system.html#varargs"><span class="Identifier">varargs</span></a><span class="Other">[</span><a href="system.html#typed"><span class="Identifier">typed</span></a><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#untyped"><span class="Identifier">untyped</span></a></pre></dt>
|
|
<dd>
|
|
|
|
Mutates <tt class="docutils literal"><span class="pre"><span class="Identifier">v</span></span></tt>, with the bits at positions <tt class="docutils literal"><span class="pre"><span class="Identifier">bits</span></span></tt> set to 0.
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">var</span> <span class="Identifier">v</span> <span class="Operator">=</span> <span class="BinNumber">0b0000_1111'</span><span class="Identifier">u8</span>
|
|
<span class="Identifier">v</span><span class="Operator">.</span><span class="Identifier">flipBits</span><span class="Punctuation">(</span><span class="DecNumber">1</span><span class="Punctuation">,</span> <span class="DecNumber">3</span><span class="Punctuation">,</span> <span class="DecNumber">5</span><span class="Punctuation">,</span> <span class="DecNumber">7</span><span class="Punctuation">)</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">v</span> <span class="Operator">==</span> <span class="BinNumber">0b1010_0101'</span><span class="Identifier">u8</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L338" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L338" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
<div id="setBits-macros-all">
|
|
<div id="setBits.m,typed,varargs[typed]">
|
|
<dt><pre><span class="Keyword">macro</span> <a href="#setBits.m%2Ctyped%2Cvarargs%5Btyped%5D"><span class="Identifier">setBits</span></a><span class="Other">(</span><span class="Identifier">v</span><span class="Other">:</span> <a href="system.html#typed"><span class="Identifier">typed</span></a><span class="Other">;</span> <span class="Identifier">bits</span><span class="Other">:</span> <a href="system.html#varargs"><span class="Identifier">varargs</span></a><span class="Other">[</span><a href="system.html#typed"><span class="Identifier">typed</span></a><span class="Other">]</span><span class="Other">)</span><span class="Other">:</span> <a href="system.html#untyped"><span class="Identifier">untyped</span></a></pre></dt>
|
|
<dd>
|
|
|
|
Mutates <tt class="docutils literal"><span class="pre"><span class="Identifier">v</span></span></tt>, with the bits at positions <tt class="docutils literal"><span class="pre"><span class="Identifier">bits</span></span></tt> set to 1.
|
|
<p><strong class="examples_text">Example:</strong></p>
|
|
<pre class="listing"><span class="Keyword">var</span> <span class="Identifier">v</span> <span class="Operator">=</span> <span class="BinNumber">0b0000_0011'</span><span class="Identifier">u8</span>
|
|
<span class="Identifier">v</span><span class="Operator">.</span><span class="Identifier">setBits</span><span class="Punctuation">(</span><span class="DecNumber">3</span><span class="Punctuation">,</span> <span class="DecNumber">5</span><span class="Punctuation">,</span> <span class="DecNumber">7</span><span class="Punctuation">)</span>
|
|
<span class="Identifier">doAssert</span> <span class="Identifier">v</span> <span class="Operator">==</span> <span class="BinNumber">0b1010_1011'</span><span class="Identifier">u8</span></pre>
|
|
<a href="https://github.com/nim-lang/Nim/tree/devel/lib/pure/bitops.nim#L314" class="link-seesrc" target="_blank">Source</a>
|
|
<a href="https://github.com/nim-lang/Nim/edit/devel/lib/pure/bitops.nim#L314" class="link-seesrc" target="_blank" >Edit</a>
|
|
|
|
</dd>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</dl>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<div class="twelve-columns footer">
|
|
<span class="nim-sprite"></span>
|
|
<br>
|
|
<small style="color: var(--hint);">Made with Nim. Generated: 2025-12-28 15:55:03 UTC</small>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script defer data-domain="nim-lang.org" src="https://plausible.io/js/plausible.js"></script>
|
|
|
|
</body>
|
|
</html>
|