
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Binary to original string conversion in JavaScript
We are required to write a JavaScript function that takes in a string that represents a binary code. The function should return the alphabetical representation of the string.
For example −
If the binary input string is −
const str = '1001000 1100101 1101100 1101100 1101111 100000 1010111 1101111 1110010 1101100 1100100';
Then the output should be −
const output = 'Hello World';
Example
The code for this will be −
const str = '1001000 1100101 1101100 1101100 1101111 100000 1010111 1101111 1110010 1101100 1100100'; const binaryToString = (binary = '') => { let strArr = binary.split(' '); const str = strArr.map(part => { return String.fromCharCode(parseInt(part, 2)); }).join(''); return str; }; console.log(binaryToString(str));
Output
And the output in the console will be −
Hello World
- Related Articles
- Decimal to binary conversion using recursion in JavaScript
- String to binary in JavaScript
- Binary to BCD conversion in 8051
- BCD to binary conversion in 8051
- Binary Tree to Binary Search Tree Conversion in C++
- Decimal to Binary conversion\n
- Converting string to a binary string - JavaScript
- Decimal to binary list conversion in Python
- Interchanging a string to a binary string in JavaScript
- Program for Binary To Decimal Conversion in C++
- Program for Decimal to Binary Conversion in C++
- Conversion of Binary to Gray Code\n
- Conversion of Gray Code to Binary\n
- C Program for Decimal to Binary Conversion?
- Decimal to Binary conversion using C Programming

Advertisements