You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ramesh Fadatare edited this page Aug 11, 2020
·
1 revision
In this example, we will write a JavaScript function to convert Decimal number to Binary number.
JavaScript Convert Decimal to Binary
functiondecimalToBinary(num){varbin=[]while(num>0){bin.unshift(num%2)num>>=1// basically /= 2 without remainder if any}console.log('The decimal in binary is '+bin.join(''))}decimalToBinary(2)decimalToBinary(7)decimalToBinary(35)
Output
The decimal in binary is 10
The decimal in binary is 111
The decimal in binary is 100011