How to toggle a bit at specific position in TypeScript

1 Answer

0 votes
function get_bits(n: number): string {
    return (n >>> 0).toString(2);
}

let n: number = 365;
const pos: number = 2;

console.log(get_bits(n));

n ^= (1 << pos);

console.log(get_bits(n));


/*
run:
     
101101101
101101001
      
*/

 



answered Apr 3 by avibootz
...