Set Bit
Learn Set Bit (Bit Manipulation, Data Structures & Algorithms) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
Turning ON a Specific Bit To SET bit i (force it to 1, regardless of its current value): OR the number with a mask that has ONLY bit i set - num | (1 << i) . OR-ing with 0 leaves other bits unchanged; OR-ing with 1 forces that bit to 1.