I do not want to encode a string
to a byte[]
. I want to turn a string
of hex numbers to a byte[]
. How can I do that?
Note: I again repeat I do not want to use Encoding.UTF8.GetBytes()
or any other encoding.
A sample string
is detailed below:
0x42A2C6A046057454C2D1AB2CE5A0147ACF1E728E1888367CF3218A1D513C72E582DBDC7F8C4674777CA148E4EFA0B4944BB4998F446724D4F56D96B507EAE619
How can I convert this string
to a byte[]
of the numbers in the string.
There is no unambiguous way to convert a string to a byte array, that's why you need to use the Encoding
class. In your case, you can use Encoding.ASCII.GetBytes()
, because you only have characters from the ASCII charset.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.