Skip to content

Commit 72b0d35

Browse files
committed
Create hex2bin.js
hex2bin() is new in PHP 5.4.0 http://php.net/manual/ro/function.hex2bin.php
1 parent 4b349ff commit 72b0d35

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

functions/strings/hex2bin.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
function hex2bin(s) {
2+
// discuss at: http://phpjs.org/functions/hex2bin/
3+
// original by: Dumitru Uzun (http://duzun.me)
4+
// example 1: bin2hex('44696d61');
5+
// returns 1: 'Dima'
6+
// example 2: bin2hex('00');
7+
// returns 2: '\x00'
8+
9+
var ret = [], i = 0, l;
10+
11+
s += '';
12+
13+
for ( l s.length ; i < l; i+=2 ) {
14+
ret.push(parseInt(s.substr(i, 2), 16));
15+
}
16+
17+
return String.fromCharCode.apply(String, ret);
18+
}

0 commit comments

Comments
 (0)