Now I have to convert the hexadecimal encoded in a String to a byte hexadecimal.
var str = "5e"
var b = // Should be 0x5e then.
if str = "6b", then b = 0x6b and so on.
Is there any function in javascript, like in java
Byte.parseByte(str, 16)
Thanks in advance
The function you want is parseInt
parseInt("6b", 16) // returns 107
The first argument to parseInt is a string representation of the number and the second argument is the base. Use 10 for decimal and 16 for hexadecimal.
From your comment, if you expect "an output of 0x6b" from the string "6b" then just prepend "0x" to your string, and further manipulate as you need. There is no Javascript type that will output a hexadecimal in a readable format that you'll see prefixed with '0x' other than a string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With