Jedhi Posted July 6, 2004 Posted July 6, 2004 string data = "123 456"; byte[] byteArray = ASCIIEncoding.ASCII.GetBytes(data); I want to convert a string to byte array, but my problem is that I get all the characters in Ascii instead of hex or dec. How do I fix that ?? Quote
Administrators PlausiblyDamp Posted July 6, 2004 Administrators Posted July 6, 2004 Just to clarify - You would want the byte array to contain the numbers 1,2,3,4,5,6? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Jedhi Posted July 6, 2004 Author Posted July 6, 2004 Just to clarify - You would want the byte array to contain the numbers 1' date='2,3,4,5,6?[/quote'] Yes. I've done as below, but I do not know if there is any smarter way to do it ! string [] data = null; data = data.Split(' '); byte[] barray = new byte[data.Length]; int i = 0; foreach (string s in data) { barray[i++] = Convert.ToByte(s); } Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.