10 examples of 'javascript hex to decimal' in JavaScript

Every line of 'javascript hex to decimal' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
302function toHex(decimal) {
303 // TODO: ugly! replace with something faster
304 let hex = new BN(decimal, 10).toString(16);
305 if ((Math.floor(hex.length / 2) * 2) !== hex.length) {
306 hex = `0${hex}`;
307 }
308 return hex;
309}
203function decimalToHex(value) {
204 value = parseInt(value).toString(16);
205 if (value == null) {
206 return null;
207 }
208 if (value.length == 1) {
209 value = '0' + '' + value;
210 }
211 return value;
212}
1032function convertDecimalToHex(d) {
1033 return Math.round(parseFloat(d) * 255).toString(16);
1034}
10var dec2hex = function decimalToHexString(number){
11 if (number < 0){
12 number = 0xFFFFFFFF + number + 1;
13 }
14
15 return number.toString(16);
16};
81function decimalToHexString(n) {
82 n = Number(n);
83 var h = "";
84 for (var i = 4; i >= 0; i--) {
85 if (n >= Math.pow(16, i)) {
86 var t = Math.floor(n / Math.pow(16, i));
87 n -= t * Math.pow(16, i);
88 if ( t >= 10 ) {
89 if ( t == 10 ) { h += "A"; }
90 if ( t == 11 ) { h += "B"; }
91 if ( t == 12 ) { h += "C"; }
92 if ( t == 13 ) { h += "D"; }
93 if ( t == 14 ) { h += "E"; }
94 if ( t == 15 ) { h += "F"; }
95 } else {
96 h += String(t);
97 }
98 } else {
99 h += "0";
100 }
101 }
102 return h;
103}
68export function decimalToHex(decimalArr) {
69 return Array.from(decimalArr).map(item => (Array(2).join(0) + item.toString(16)).toUpperCase().slice(-2));
70}
1763function convertHexToDecimal(h) {
1764 return (parseIntFromHex(h) / 255);
1765}
141function hexify (decimalString) {
142 const hexBN = new BN(decimalString, 10)
143 return '0x' + hexBN.toString('hex')
144}
5function dec2hex(dec) {
6 // Generate random string/characters
7 // dec2hex :: Integer -> String
8 return ('0' + dec.toString(16)).substr(-2);
9}
44setValueFromDecimal(value){
45 assert(TypeCheck.isNumber(value), 'Value needs to be a number');
46
47 this.setValue(value.toString(16));
48}

Related snippets