ludic/op-bitwise.html
2026-09-17 22:10:03 +00:00

31 lines
No EOL
2.3 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

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

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bitwise — Ludic</title>
<meta name="description" content="Bit-level and, or, xor, not, and shifts — with Go-style precedence.">
<link rel="stylesheet" href="base.css">
<link rel="stylesheet" href="docs.css">
</head>
<body>
<header class="nav"><div class="wrap nav-in"><a class="brand" href="index.html"><span class="logo">L</span> Ludic</a><button class="nav-toggle" aria-label="Toggle menu" aria-expanded="false">☰</button><nav class="nav-links"><a href="index.html">Home</a><a href="api.html">API Reference</a><a class="nav-cta" href="https://git.workshopsoft.io/workshopsoft/ludic">Source ↗</a></nav></div></header>
<main class="wrap item">
<div class="crumbs"><a href="api.html">API Reference</a> <span>›</span> <a href="api.html#operators">Operators &amp; tokens</a> <span>›</span> <span class="here">Bitwise</span></div>
<div class="item-head">
<span class="kind-badge kind-operator">operator</span>
<h1 id="top">Bitwise</h1>
</div>
<code class="sig">&amp; | ^ ~ &lt;&lt; &gt;&gt;</code>
<div class="desc"><p>The bitwise operators work on the bits of an <code>int</code>: <code>&</code> (and), <code>|</code> (or), <code>^</code> (xor), <code>~</code> (not), <code><<</code> (shift left), and <code>>></code> (a logical/unsigned shift right). They are the tools for flag sets, packing several small values into one integer, and fast multiply/divide by powers of two. Precedence is Go-style: <code><<</code>, <code>>></code>, and <code>&</code> bind like <code>*</code> (tightly), while <code>|</code> and <code>^</code> bind like <code>+</code>, and all of them bind <b>tighter than comparison</b> — so <code>flags & MASK == 0</code> means <code>(flags & MASK) == 0</code> with no parentheses.</p></div>
<div class="examples"><h2>Example</h2><pre data-lang="ludic">const FLAG_POISONED: int = 1
const FLAG_SHIELDED: int = 2
var status_flags: int = FLAG_POISONED | FLAG_SHIELDED
var is_shielded: bool = status_flags &amp; FLAG_SHIELDED != 0</pre></div>
<a class="back" href="api.html">← All symbols</a>
</main>
<script src="ludic-highlight.js"></script>
<script>Ludic.highlightAll(); Ludic.installCards(); Ludic.flashTarget();</script>
</body></html>