Convert a number to a hexadecimal string with:

hexString = yourNumber.toString(16);

And reverse the process with:

yourNumber = parseInt(hexString, 16);
Answer from Prestaul on Stack Overflow
🌐
GitHub
gist.github.com › agirorn › 0e740d012b620968225de58859ccef5c
Convert decimal to hex in JavaScript. · GitHub
JavaScript already offers a "native way" of doing it: // our decimal number const nr = 999999999; // convert to hex const hex = nr.toString(16); // back to dec: const decNr = parseInt(hex, 16); However, the example above can only handle numbers till Number.MAX_SAFE_INTEGER => 9007199254740991
Discussions

Int to hex string in javascript - Stack Overflow
I want to convert an number (integer) to a hex string 2 (0x02) to "\x02" or 62 (0x0062) to "\x62" How can I do that correctly? More on stackoverflow.com
🌐 stackoverflow.com
JavaScript can't output non-string hex values, can it?
> (0xFF0000 + 0x0000FF).toString(16) "ff00ff" 32, 0x20, 0o40 (ES6), and 0b100000 (ES6) are the same number. JavaScript supports decimal, hexadecimal, octal, and binary numeric literals. If one of those representations is more convenient for what you want to do, you can use one of those. If you need a different representation when you output a result, you'll have to use toString with the desired base as parameter. More on reddit.com
🌐 r/javascript
13
2
November 3, 2015
Iterating over a range in hex
tl;dr how do I create a for loop in which I can call a function: foo('\x01') to foo('\x21') ? Just in case you don't see my answer further below: for n in range(0x22): c = chr(n) foo(c) More on reddit.com
🌐 r/Python
12
1
August 5, 2014
Convert from Hex to Decimal
Use uint instead of int https://sharplab.io/#v2:EYLgxg9gTgpgtADwGwBYA0AXEUCuA7NAExAGoAfAAQCYBGAWAChGBLPDAAmfYF52BhCHgBuMKBgB0AFQgBJNgGYqACgBEABgQAzbTu0q07GkgCUAbkY5WHHD36CRYqRACqcjItUbdu/YZOmgA=== More on reddit.com
🌐 r/csharp
9
0
September 3, 2024
🌐
Dirask
dirask.com › posts › JavaScript-convert-int-to-hex-p5Ndxj
JavaScript - convert int to hex
JavaScript. ... // ONLINE-RUNNER:browser; const intNumber = 26085; const hexNumber = intNumber.toString(16); // hex number as string console.log(hexNumber); // 65e5
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-convert-number-to-hex
Convert a number to Hexadecimal in JavaScript | bobbyhadz
The toString method will return the string representation of the number in hexadecimal form.
Find elsewhere
🌐
TutorialsPoint
tutorialspoint.com › how-to-convert-decimal-to-hex-in-javascript
How to convert decimal to hex in JavaScript?
April 21, 2023 - The toString(16) method is the preferred approach for converting decimal to hexadecimal in JavaScript due to its simplicity and efficiency.
🌐
Coolaj86
coolaj86.com › articles › convert-decimal-to-hex-with-js-bigints
Convert Decimal Strings to Hex with JS BigInts
December 12, 2018 - With the introduction of native BigInts (also known as Big Nums or Arbirtrary-Precision Numbers), in JavaScript, it's now easy to convert from arbitrarily-large ints to hex (which is the gateway drug to typed arrays).
🌐
30 Seconds of Code
30secondsofcode.org › home › javascript › number › decimal to hexadecimal
JavaScript - Convert decimal number to hexadecimal - 30 seconds of code
September 21, 2022 - Numeric values are represented in decimal format by default, when converted to strings. If you want to display them in hexadecimal format, you can use Number.prototype.toString() and pass the base you want to use (16) as an argument.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-convert-decimal-to-hex-in-javascript
How to convert decimal to hex in JavaScript ? - GeeksforGeeks
July 11, 2025 - Given a number and the task is to convert the number from decimal to hex. This can be done by using toString() method. It takes the parameter which is the base of the converted string.
🌐
GitHub
gist.github.com › faisalman › 4213592
Convert From/To Binary/Decimal/Hexadecimal in JavaScript · GitHub
const convert = { bin2dec : s => parseInt(s, 2).toString(10), bin2hex : s => parseInt(s, 2).toString(16), dec2bin : s => parseInt(s, 10).toString(2), dec2hex : s => parseInt(s, 10).toString(16), hex2bin : s => parseInt(s, 16).toString(2), hex2dec : s => parseInt(s, 16).toString(10) }; convert.bin2dec('111'); // '7' convert.dec2hex('42'); // '2a' convert.hex2bin('f8'); // '11111000' convert.dec2bin('22'); // '10110' ... I turned this into an NPM library if anybody wants to use it : https://www.npmjs.com/package/aybabtu
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › parseInt
parseInt() - JavaScript - MDN Web Docs
If not NaN, the return value will be the integer that is the first argument taken as a number in the specified radix. (For example, a radix of 10 converts from a decimal number, 8 converts from octal, 16 from hexadecimal, and so on.) The radix argument is converted to a number. If it's unprovided, or if the value becomes 0, NaN or Infinity (undefined is coerced to NaN), JavaScript assumes the following:
🌐
Jamesqquick
jamesqquick.com › blog › convert-number-from-decimal-to-hexadecimal
Convert Number from Decimal to Hexadecimal in JavaScript (and visa versa)
June 18, 2020 - If you have a decimal number that you want to convert to hexidecimal, you can call the toString() function with the number and pass in a target base (binary, decimal, hexedecimal, etc.). This parameter is known as the radix.
🌐
Sabe
sabe.io › blog › javascript-hex-to-decimal
Convert Hex to Decimal in JavaScript - Sabe.io
January 18, 2022 - We've seen how you can use parseInt() in JavaScript to convert a hexadecimal number to decimal.
🌐
YouTube
youtube.com › code 2020
JavaScript tips — Convert strings of hex digits into numbers - YouTube
Convert strings of hex digits into numbers using #JavaScript's built-in parseInt functionFor basic uses you can simply call parseInt with a string that start...
Published: September 23, 2022
Views: 1K
🌐
YouTube
youtube.com › watch
How to convert Decimal to Hexadecimal in JavaScript - YouTube
How to convert Decimal to Hexadecimal in JavaScriptLearn to convert decimal to hexadecimal in JavaScript with this simple and easy to follow tutorial. Discov...
Published: February 1, 2023
🌐
Medium
medium.com › @saumya07013 › exploring-the-world-of-javascript-hexadecimal-operations-7501a24cc3c8
Exploring The World Of Javascript Hexadecimal Operations | by Saumya | Medium
October 1, 2024 - Here, 0x1A represents the decimal value 26. When you log hexNumber, it prints 26, as JavaScript automatically converts it to a decimal when displaying. JavaScript provides methods to convert between decimal and hexadecimal.
🌐
Tutorial Republic
tutorialrepublic.com › faq › how-to-convert-decimal-values-to-hexadecimal-in-javascript.php
How to Convert Decimal Values to Hexadecimal in JavaScript
// Simple function to convert decimal to hexadecimal function dec2Hex(dec) { return Math.abs(dec).toString(16); } // Testing some values console.log(dec2Hex(960)); // Output: 3c0 console.log(dec2Hex(255)); // Output: ff console.log(dec2Hex(15)); ...