# [Code Example] Convert decimal to binary in javascript & reactjs

To convert a decimal number to a binary number in javascript & reactjs, you can follow these steps –

1. Take a empty string value to hold output.
2. Run a loop till our decimal number is greater than 0.
3. Take mod of decimal number by 2 and prepend it to output string.
4. set decimal number equals to decimal number / 2

Code Example –

``````function decimalToBinary(x) {
var parsed = parseInt(x, 10);
if (isNaN(parsed)) { return 0; }

hexstr = ""
while(parsed > 0) {
hexstr = (parsed % 2) + hexstr
parsed = parseInt(parsed / 2)
}

return hexstr;
}

console.log(decimalToBinary('56'));
// expected output: "111000"
``````

Source: MSDN

Get only the best articles delivered to your mail

## [Code Example] Remove duplicate elements from array using bash script

In this article we will provide you the bash script code to remove duplicate elements from array. In this approach, the order of list items may change. Code Example –…

## [Code Example] vector int or pair int,int, which is better?

In this article we will understand which is better – vector<vector<int>> or vector<pair<int, int>>. vector has dynamic size so end up using heap but pair is fixed so there is…

## [Code Example] Create Loader in React Native

In this article we will provide you code to create loader in your react native mobile app. Loaders are created using <ActivityIndicator> component. You can customize its size, color, animation…

## [Code Example] Ways to run javascript on your computer

In this article we will see how you can run javascript on your computer system. We will discuss about 2 ways to run Javascript – Using Google Chrome Developer Console.…

## [Code Error] RangeError: toString() radix argument between 2 and 36

Get code to resolve the RangeError: toString() radix argument must be between 2 and 36. Radix in parseInt() or toString() cannot be less than 2 and greater than 36. This…

## [Code Example] valueerror: cannot reindex from a duplicate axis

Table of Contents Hide Why duplicates are allowed?Code ExampleSolutionRelated Posts: In this article I will quickly provide you some code examples which will help you in resolving valueerror: cannot reindex…