How to convert a hex string to bytes array in Crystal? -


how can convert hex string bytes array in crystal?

example:

87 a3 69 6e 74 01 a5 66 6c 6f 61 74 cb 3f e0 00 00 00 00 00 00 a7 62  6f 6f 6c 65 61 6e c3 a4 6e 75 6c 6c c0 a6 73 74 72 69 6e 67 a7 66 6f 6f 20 62 61 72 a5 61 72 72 61 79 92 a3 66 6f 6f a3 62 61 72 a6 6f 62 6a 65 63 74 82 a3 66 6f 6f 01 a3 62 61 7a cb 3f e0 00 00 00 00 00 00 

like this:

hexstring = "87 a3 69 6e 74 01 a5 66 6c 6f 61 74 cb 3f e0 00 00 00 00 00 00 a7 62  6f 6f 6c 65 61 6e c3 a4 6e 75 6c 6c c0 a6 73 74 72 69 6e 67 a7 66 6f 6f 20 62 61 72 a5 61 72 72 61 79 92 a3 66 6f 6f a3 62 61 72 a6 6f 62 6a 65 63 74 82 a3 66 6f 6f 01 a3 62 61 7a cb 3f e0 00 00 00 00 00 00" bytes_array = hexstring.split.map(&.to_u8(16)) pp bytes_array, bytes_array.class 

https://play.crystal-lang.org/#/r/19dh


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -