How to restore hexadecimal string to hexadecimal code in java

  1. there is a requirement to process the hexadecimal code returned by the hardware as a program and convert the hexadecimal code into a string

for example,: FA FB 2F 00 00 00 01 20 05 01 00 11 01 25 3F 00 00 38 00 00 00 02 12 00 00 00 03 00 00 00 02 01 50 02 50 08 25 00 00 00 02 07 10 02 63 19 00 00 00 72 4B

  1. the problem encountered when transferring the hexadecimal string back to the hexadecimal code is as follows:

clipboard.png

Debug tool receiving is inconsistent with sending

ask how to convert the hexadecimal string back to hexadecimal code.

Jun.02,2021

like this?

"FA FB 2F 00 00 00 00 00 01 20 05 01 00 11 01 25 3F 00 00 38 00 00 00 02 12 21 00 00 00 00 00 03 00 00 00 00 00 00 00 02 01 07 50 02 50 08 25 00 00 00 00 00 02 07 10 02 63 19 26 00 00 00 00 00 00 72 4B"
.split(/ /g)
.map(c=>String.fromCharCode(parseInt("0x"+c)))
.map(c=>("0"+c.charCodeAt(0).toString(16).toUpperCase()).slice(-2))
.join(" ")

is java, ignore this answer.

Menu