Skip to content
Subhajit Sahu edited this page Jan 24, 2021 · 7 revisions

Set bits as per mask. 📰 📘

Alternatives: set, setAs.
Similar: get, set, toggle.


Bit.setAs(x, m, [f]);
// x: an int or long
// m: bit mask
// f: bit value (1)
import io.github.javaf.*;

Bit.setAs(8, 2, 1);
// 10 (0x8 set 0x2 ⇒ 0xA)

Bit.setAs(15, 3, 0);
// 12 (0xF clear 0x3 ⇒ 0xC)

Bit.setAs(0x1234, 0x430, 1);
// 5684 (0x1234 set 0x430 ⇒ 0x1634)


References

Clone this wiki locally