0

I found this code on W3schools for converting decimal into binary.

function dec2bin(dec){
return (dec >>> 0).toString(2);
}

I don't understand what is the purpose for making zero fill right shift in this case? What is the use of setting the shift to 0 (i.e. dec >>> 0) since as I know it doesn't push any binary digit to the right at all?

I am a JS beginner. Thanks!

4
  • 1
    It converts a number to an integer. It’s the same as dec | 0 or ~~dec. Commented Mar 7, 2017 at 9:27
  • 1
    @Xufox, not only, it makes a 32 bit number. Commented Mar 7, 2017 at 9:28
  • you can manually check difference between >> and >>> and compare results Commented Mar 7, 2017 at 9:35
  • @Banzay This question isn’t about the difference between >> and >>>. Commented Mar 7, 2017 at 9:40

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.