Q:

Write a JavaScript program to reverse the order of the bits in a given integer

0

Write a JavaScript program to reverse the order of the bits in a given integer. 
56 -> 111000 after reverse 7 -> 111
234 -> 11101010 after reverse 87 -> 1010111

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

function mirror_bits(n) {
  return parseInt(n.toString(2).split("").reverse().join(""), 2);
}

console.log(mirror_bits(56));
console.log(mirror_bits(234));

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now