Can anyone please tell me equivalent Nodejs code to convert hex string to byte array which is in Java
public static byte[] hexStringToByteArray(String s) {
byte[] b = new byte[s.length() / 2];
for (int i = 0; i < b.length; i++) {
int index = i * 2;
int v = Integer.parseInt(s.substring(index, index + 2), 16);
b[i] = (byte) v;
}
return b;
}
You can use Buffer.from(str, [encoding]) to perform the conversion.
Buffer.from(str, 'hex');
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