Search
 
SCRIPT & CODE EXAMPLE
 

RUST

Counting bits Kernighan style

// Counting bits Kernighan style
fn bit_count(mut n: usize) -> usize {
    let mut cnt = 0;
    while n > 0 {
        n &= n - 1;
        cnt += 1;
    }
    cnt
}

fn main() {
    println!("Bit count = {} ", bit_count(254));
}
Comment

PREVIOUS NEXT
Code Example
Rust :: rust Clean way to get Option::unwrap_or_else behaviour with an Option<&T 
Rust :: armanriazi•rust•error•E0615•attempted to take value of method `collect` on type 
Rust :: armanriazi•rust•unsafe•function•or•method 
Rust :: rust what does the double colon mean? 
Rust :: how to get text from a file and store it in a variable rust 
Rust :: armanriazi•rust•trait•external•implement•coherence•orphan 
Rust :: armanriazi•rust•thread•rayon•join•workstealing 
Rust :: armanriazi•rust•unsafe•safeabstraction 
Rust :: armanriazi•rust•concept•jargon 
Rust :: initializing array rust 
Lua :: roblox make a rainbow part 
Lua :: how to choose a random item from a table lua 
Lua :: how to make a part rotate roblox 
Lua :: luau how to make debounce 
Lua :: my second long scripting 
Lua :: roblox studio random part color 
Lua :: for i = 1 to n roblox 
Lua :: glua varargs 
Lua :: string.match roblox 
Lua :: lua f animation 
Lua :: roblox touch part kill script 
Lua :: how to make a day/night script roblox 
Lua :: awesomewm wibar configuration transparent 
Lua :: lua class example 
Matlab :: matlab how to get object type 
Matlab :: matlab 1d matrix declarationg 
Basic :: how to add basic authentication on haproxy backend server 
Basic :: dos assign command output to variable (when output is of multiple lines) 
Elixir :: phoenix run server 
Scala :: scala get file from url as string 
ADD CONTENT
Topic
Content
Source link
Name
9+4 =