summaryrefslogtreecommitdiff
path: root/bits.zig
blob: 64f7d8b94978a0b43dab0d74aa564371bcef8c34 (plain) (blame)
1
2
3
4
5
6
7
8
9
const math = @import("std").math;

pub fn set(comptime Int: type, num: Int, bit: math.Log2Int(Int), value: bool) Int {
    return (num & ~(Int(1) << bit)) | (Int(value) << bit);
}

pub fn get(comptime Int: type, num: Int, bit: math.Log2Int(Int)) bool {
    return ((num >> bit) & 1) != 0;
}