Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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 ??

Posted
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);

}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...