Skip to content

Latest commit

 

History

History
38 lines (38 loc) · 1.07 KB

bitwise_review.md

File metadata and controls

38 lines (38 loc) · 1.07 KB

Hexadecimal

All 1's

All 1's unsigned

Turn off bits (leaving remainder untouched)

Turn on bits

Create a mask with 0's in the rightmost n bits

Create a mask with 0's in the leftmost n bits

Create a mask with 1's in the rightmost n bits

Create a mask with 1's in the leftmost n bits

Move a range field to the right end of a word

Set a bit

Clear a bit

Toggle a bit

Test a bit

Naive left shift with rotate

Safe left shift with rotate

Drop lowest set bit

Clear least significant bit

Swap bits i & j

Count number of set bits (Hamming Weight for bit strings or popcount/population count)

Sign of an int

Detect if integers have opposite signs

Absolute value of an int

Find the minimum

Find the maximum

Is power of two

Absolute value of an int

Round up to next power of 2

Properties of XOR

Identity -> a number XOR'ed with 0 returns the number

Bitwise negation

Inverting the identity

Associativity

Commutativity

Swap

Bitwise XOR equivalent

One's complement

Two's complement