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

1 Answer

0 votes
const value: number = 0b1101_0110;
const lower4: number = 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
...