We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 4b349ff + 824de6a commit d94f3ccCopy full SHA for d94f3cc
functions/strings/hex2bin.js
@@ -0,0 +1,23 @@
1
+function hex2bin(s) {
2
+ // discuss at: http://phpjs.org/functions/hex2bin/
3
+ // original by: Dumitru Uzun (http://duzun.me)
4
+ // example 1: hex2bin('44696d61');
5
+ // returns 1: 'Dima'
6
+ // example 2: hex2bin('00');
7
+ // returns 2: '\x00'
8
+ // example 3: hex2bin('2f1q')
9
+ // returns 3: false
10
+
11
+ var ret = [], i = 0, l;
12
13
+ s += '';
14
15
+ for ( l = s.length ; i < l; i+=2 ) {
16
+ var c = parseInt(s.substr(i, 1), 16);
17
+ var k = parseInt(s.substr(i+1, 1), 16);
18
+ if(isNaN(c) || isNaN(k)) return false;
19
+ ret.push( (c << 4) | k );
20
+ }
21
22
+ return String.fromCharCode.apply(String, ret);
23
+}
0 commit comments