How to get the 4 least significant bits in a byte with JavaScript

1 Answer

0 votes
const value = 0b11010110;
const lower4 = value & 0x0F;

console.log("value  (dec):", value);
console.log("lower4 (dec):", lower4);

console.log("value  (bin): ", value.toString(2).padStart(8, "0"));
console.log("lower4 (bin): ", lower4.toString(2).padStart(4, "0"));

 
 
 
/*
run:
 
value  (dec): 214
lower4 (dec): 6
value  (bin):  11010110
lower4 (bin):  0110
 
*/

 



answered Dec 28, 2025 by avibootz
...