


How to convert decimal number to binary number using JavaScript
The following functions can convert decimal numbers to binary numbers:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
twenty one
twenty two
twenty three
twenty four
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include
#include
#define MAX 33
usingnamespacestd;
/* Convert decimal number to binary number (string representation) */
char*decToBin(longnum);
intmain()
{
longdec = 123456789;
cout
cout
return0;
}
/* Convert decimal number to binary number (string representation) */
char*decToBin(longnum)
{
char*arr;
chartemp;
inti, n;
arr = (char*)malloc(sizeof(char) * MAX);
n = 0;
while(num > 0)
{
arr[n ] = num % 2 '0';
num /= 2;
}
for(i=0; i { temp = arr[i]; arr[i] = arr[n-1-i]; arr[n-1-i] = temp; } arr[n] = '\0'; returnarr; } 1. Decimal number refers to a value in which all digits are composed of numbers less than 10 (0..9), such as 123, 45678, etc. A binary number refers to a numerical value in which all digits are composed of digits less than 2 (0..1), such as 10, 1011, etc. Converting a decimal number to a binary number is to convert a value composed entirely of digits less than 10 into a value composed entirely of digits less than 2. For example, the decimal number 100 is converted into a binary number 1100100. 2. The algorithm for converting decimal numbers into binary numbers is to use the Euclidean remainder method, that is, the number to be converted is divided by 2 to take the remainder, record the remainder, and use the new quotient to continue dividing by 2 to take the remainder until the number is zero. Since the remainder is less than 2, all values composed of remainders are composed of 0 and 1. Then just reverse these remainders.
The above is the detailed content of How to convert decimal number to binary number using JavaScript. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Have you ever encountered a black screen after installing a graphics driver like an Nvidia driver in Windows 10/11? Now in this post from php.cn, you can find a couple of worth trying solutions to the Nvidia driver update black screen.

KB2267602 is a protection or definition update for Windows Defender designed to fix vulnerabilities and threats in Windows. Some users reported that they were unable to install KB2267602. This post from php.cn introduces how to fix the “KB2267602 fai

Data recovery is always a heated topic. To successfully restore data from your device, you should know how it stores data. You can learn the difference between RAID recovery and hard drive recovery from this php.cn post.

File system errors commonly happen on people’s computer and the error can trigger a series of linked malfunctions. This article on php.cn Website will give you a series of fixes to targeting the file system error (-1073741521). Please keep on with yo

The Security tab in File Properties helps set different permissions for different groups and users to a file or folder. Some users find that Windows 11 Security tab missing from File Properties. This post from php.cn gives some methods to fix it.

Seeing a black folder background Windows 10/11 when you open File Explorer? In this post from php.cn Solution, you will learn a couple of useful solutions to remove the black background in folders.

Are you struggling with the “the file can’t be displayed” error when accessing the specific folder? Some users are complaining about this trouble and looking for useful measures. This article about the file can’t be displayed OneDrive from php.cn wil

Some users report that they meet the Windows Server auto-shutdown issue after the license expires. This post from php.cn teaches you how to stop expired Windows Server auto-shutdown. Now, keep on your reading.
