-
Notifications
You must be signed in to change notification settings - Fork 1
swap
Subhajit Sahu edited this page Feb 3, 2021
·
13 revisions
Swaps bit sequences. 📦 😺 🏃 📼 🌔 📜 📰 📘
bit.swap(x, i, j, [n]);
// x: an int32
// i: first bit index
// j: second bit index
// n: bit width (1)
const bit = require("extra-bit");
bit.swap(6, 1, 0);
// 5 (110 ⇒ 101)
bit.swap(0x1234, 8, 4, 4);
// 4900 (0x1234 ⇒ 0x1324)
bit.swap(0x4AAB, 8, 0, 8);
// 43850 (0x4AAB ⇒ 0xAB4A)