On Apr 12, 2:07 am, "Peter Rust" <pe...@cornerstonenw.com> wrote: > Stan, > > I just posted a comment to the SO post: > > Assuming SQLite returns a hexadecimal string that looks like > "611006F462424C4183578E51B87021", you can iterate every two characters, > slice, parseInt and push onto an array. Since every two characters > represents a byte, just write a for loop that increase the index by 2 every > time instead of by 1. You can grab the two characters via String.slice(), > like so: hex.slice(ix, ix+2). You can convert these to an integer via > parseInt(str, 16). So it would look like: > > arr = []; > > for(var ix = 0; ix < hex.length; ix = ix+2) { > > arr.push(parseInt(hex.slice(ix, ix+2), 16)); > > }
Assuming the input is character pairs of hex values, a more efficient function (removing calls to push amd slice) may be: var hexToDec = (function() { var re = /../g; return function (hexString) { var bytes = hexString.match(re); var i = bytes.length; while (i--) { bytes[i] = parseInt(bytes[i],16); } return bytes; } }()); Example: hexToDec('611006F462424C4183578E51B87021') returns: [97,16,6,244,98,66,76,65,131,87,142,81,184,112,33] -- Rob -- You received this message because you are subscribed to the Google Groups "iPhoneWebDev" group. To post to this group, send email to iphonewebdev@googlegroups.com. To unsubscribe from this group, send email to iphonewebdev+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/iphonewebdev?hl=en.