Ben Chuanlong Du's Blog

It is never too late to learn.

Manipulate Bits in Rust

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

bitvec

bitvec Addresses memory by bits, for packed collections and bitfields bitvec provides a foundational API for bitfields in Rust. It specializes standard-library data structures (slices, arrays, and vectors of bool …

Useful Rust Crates for Bit Manipulations

Things on this page are fragmentary and immature notes/thoughts of the author. Please read with your own judgement!

bytemuck

ByteMuck is a crate for mucking around with piles of bytes. It lets you safely perform "bit cast" operations between data types. That's where you take a value and just …

Bitwise Operators in Kotlin

Comments

  1. When you use 1L shl 2, shl is considered as the left-shift operator instead of a method call.

  2. Bitwise operators are computed from left to the right.

  3. Bitwise operators have relatively low priority (lower than arithmatic operators), It is suggested that you use parentheses when you mix lower precendenc (bitwise opertors, ternary opertor, etc.) and high precendenc operators together. A even better approach in Kotlin is to avoid using bitwise operators and use the corresponding methods instead.