MCPcopy Index your code
hub / github.com/careercup/ctci / updateBit

Method updateBit

java/Chapter 5/Sample_Code/Sample_Code.java:20–23  ·  view source on GitHub ↗
(int num, int i, int value)

Source from the content-addressed store, hash-verified

18 }
19
20 public static int updateBit(int num, int i, int value) {
21 int mask = ~(1 << i);
22 return (num & mask) | (value << i);
23 }
24
25 public static int clearBitsMSBthroughI(int num, int i) {
26 int mask = (1 << i) - 1;

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected