
- 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
Converting ASCII to hexadecimal in JavaScript
We are required to write a JavaScript function that takes in a string that represents a ASCII number. The function should convert the number into its corresponding hexadecimal code and return the hexadecimal.
For example −
f the input ASCII string is −
const str = '159';
Then the hexadecimal code for this should be 313539.
Example
Following is the code −
const str = '159'; const convertToHexa = (str = '') =>{ const res = []; const { length: len } = str; for (let n = 0, l = len; n < l; n ++) { const hex = Number(str.charCodeAt(n)).toString(16); res.push(hex); }; return res.join(''); } console.log(convertToHexa('159'));
Output
Following is the output on console −
313539
- Related Articles
- Converting an image to ASCII image in Python
- Convert a string to hexadecimal ASCII values in C++
- Convert Hexadecimal value String to ASCII value String in C++
- ASCII to hex and hex to ASCII converter class in JavaScript
- How to format hexadecimal Number in JavaScript?
- Converting array to set in JavaScript
- Converting degree to radian in JavaScript
- RGB color to hexadecimal color JavaScript
- Hexadecimal color to RGB color JavaScript
- Converting string to MORSE code in JavaScript
- Converting strings to snake case in JavaScript
- Converting string to an array in JavaScript
- Converting whitespace string to url in JavaScript
- Converting alphabets to Greek letters in JavaScript
- Converting any case to camelCase in JavaScript

Advertisements