Changeset 312
- Timestamp:
- 06/25/08 18:24:25 (8 weeks ago)
- Files:
-
- 1 modified
-
branches/0.5/daemon/orbited/static/hex.js (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
branches/0.5/daemon/orbited/static/hex.js
r211 r312 1 hexChars = '0123456789ABCDEF'2 3 hexToBase10 = { }4 base10ToHex = { }5 for (var i = 0; i < hexChars.length; ++i) {6 hexToBase10[hexChars[i]] = i7 base10ToHex[i] = hexChars[i]8 }9 10 1 hexToBytes = function(str) { 2 // str = str.toUpperCase() 11 3 if (str.length == 0) 12 4 return [] … … 15 7 var output = [] 16 8 for (var i =0; i < str.length; i+=2) { 17 var val = (hexToBase10[str[i]] << 4) + (hexToBase10[str[i+1]])18 output.push( val)9 target = str.charAt(i) + str.charAt(i+1) 10 output.push(parseInt(target, 16)) 19 11 } 20 12 return output … … 33 25 return output.join("") 34 26 } 35 /*36 bytesToHex = function(bytes) {37 var output = []38 for (var i = 0; i < bytes.length; ++i) {39 var byte = bytes[i]40 var hex1 = byte >> 441 output.push(base10ToHex[hex1])42 output.push(base10ToHex[byte - (hex1 << 4)])43 }44 return output.join("")45 }46 */