Skip to content

Instantly share code, notes, and snippets.

View BixinFromThisRealm's full-sized avatar
💾
saving some stuff rn

Bixin BixinFromThisRealm

💾
saving some stuff rn
View GitHub Profile
@BixinFromThisRealm
BixinFromThisRealm / bit_slice.rs
Last active June 27, 2022 20:47
A tiny but useful algorithm for getting the bits from n to k off a integer.
fn main() {
let num = slice(0b1101001, 3, 7);
println!("num = {:#b}", num); // "num = 0b1101"
}
// since all this is just some basic arithmetic
// the function should have a big O of 1.
fn slice(bits: i32, start: i32, end: i32) -> i32 {