10 examples of 'string to hex javascript' in JavaScript

Every line of 'string to hex javascript' 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
this disclaimer
52export function string2hex(string: string): number
53{
54 if (typeof string === 'string' && string[0] === '#')
55 {
56 string = string.substr(1);
57 }
58
59 return parseInt(string, 16);
60}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

636function makeHex(v) {
637 if (v < 16) { return '0' + v.toString(16); }
638 return v.toString(16);
639}
16export function hexToString(hexCode) {
17 const hex = hexCode.toString();
18 let str = '';
19 for (let i = 0; i < hex.length; i += 2) {
20 str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
21 }
22 return str;
23}
24export function Hex (value) {
25 let num = parseInt(value)
26 if (num < 0) {
27 num = 0xFFFFFFFF + num + 1
28 }
29 return num.toString(16)
30}
121function string2Hex(string) {
122 return Array.prototype.map.call(string, char => char.charCodeAt(0));
123}
19function hexToString(hex: string) {
20 let str = '';
21 for (let i = 0; i < hex.length; i += 2) {
22 str += String.fromCharCode(parseInt(hex.substr(i, 2), 16));
23 }
24 return str;
25}
195function hex(value) {
196 if (value===undefined){
197 Log.error();
198 }//endif
199 return "#" + convert.int2hex(Math.round(value.r), 2) + convert.int2hex(Math.round(value.g), 2) + convert.int2hex(Math.round(value.b), 2);
200}//function
3function getLittleEndianHex(value) {
4 var result = []
5 for (var bytes = 4; bytes > 0; bytes--) {
6 result.push(String.fromCharCode(value & 255))
7 value >>= 8
8 }
9 return result.join('')
10}
40function int2hex(intvalue, padding = 2) {
41 if (intvalue < 0)
42 intvalue = 0;
43 hval = intvalue.toString(16);
44 while (hval.length < padding)
45 hval = "0" + hval;
46 return hval;
47}
198function stringToHex (s) {
199 var r = "0x";
200 var hexes = new Array ("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f");
201 for (var i=0; i<s.length; i++) {r += hexes [s.charCodeAt(i) >> 4] + hexes [s.charCodeAt(i) & 0xf];}
202 return r;
203}

Related snippets