system.byte[] error c# when converting from string to byte -
i want convert string byte[] in c# , of previous topics use code : string s = "0a"; system.text.asciiencoding encode = new system.text.asciiencoding(); byte[] b = encode.getbytes(s); console.writeline(b);
but when run code prints : " system.byte[]"
i think may have deciphered question. trying hex digits of string array?
i'm assuming want take 2-digit hex values string , convert each lot bytes. if not, i'm lost else. please note have not included error checking!
byte[] data = new byte[s.length/2]; for(int = 0; < s.length/2; ++i) { byte val = byte.parse(s.substring(i*2,2), system.globalization.numberstyles.hexnumber); data[i] = val; } foreach(byte bv in data) { console.writeline(bv.tostring("x")); }
Comments
Post a Comment