Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script type="text/Javascript">
- function extractBit() {
- var n = document.getElementById("extractBit").value;
- var p= document.getElementById("extractPos").value;
- var mask = 1 << p; // moving the first bit to the left by bPos positions.
- var result= (n & mask) != 0 ? 1 : 0; // we are using the & operator to see if the bit is 1
- alert("The " + p+ " bit of the number " + n + " is: " + result)
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement