About a week ago I found a really nice converter from text to hexadecimal.
However, I didn't test text with newlines. Suddenly my nodejs app returned this: fÚf
instead of:
f
f
the hexadecimal, according to string-functions.com should be 660d0a0d0a66 but my application returns 66da66
here is my "toHex" and "toText" code. This kind of converting isn't my strongest point.
var toHex = function toHex (str) {
var hex = ''
for (var i = 0; i < str.length; i++) {
hex += '' + str.charCodeAt(i).toString(16)
}
return hex
}
var toText = function (hexx) {
var hex = hexx.toString() // force conversion
var str = ''
for (var i = 0; i < hex.length; i += 2) {
str += String.fromCharCode(parseInt(hex.substr(i, 2), 16))
}
return str
}
edit: when I insert 660d0a0d0a66 directly into my converter it convert to: f f, so there is a problem there as well....
via Rachelle
No comments:
Post a Comment