Home > Net >  If the string of a string into hexadecimal ASCII
If the string of a string into hexadecimal ASCII

Time:10-08

String data is that #="+ A + Spaces 30 + space + + space + 30 54

Converted to ASCII, get the ASCII is 23 41 20 30 20 to 35 33 34 20 33 30


Could you tell me how to write, this function will

CodePudding user response:

 
Var bytes=Encoding. The ASCII. GetBytes (" # + 30 + space + A + Spaces 54 + space + 30 ");

CodePudding user response:

Var bytes=Encoding. The ASCII. 30 54 GetBytes ("=\ "# A 30");

CodePudding user response:

Hexadecimal or decimal in no difference in the system, actually only 2 into the computer system, decimal, it takes the compiler under translation, computer can identify you as long as the final presentation into hexadecimal

CodePudding user response:

To make a test is not clear?

 
Using System;
Using System. Linq;
Using System. The Text;

Static class Program
{
The static void Main ()
{
Byte [] bytes1=Encoding. The ASCII. GetBytes (" # A 30 54 30 ");
Byte [] bytes2=new byte [] {0 x23, 0 x41, 0 x20, 0 x33, 0 x30, 0 x20, 0 x35, 0 x34, 0 x20, 0 x33, 0 x30};

Var sequence exactly equal=bytes1. SequenceEqual (bytes2);
Console. WriteLine (sequence exactly equal);//true
}
}

CodePudding user response:

Why the above four master a also didn't help me make to
Is converted to decimal two masters wrote before, what I need is converted to hexadecimal,
The third master is to help you master before wash white, hexadecimal, customers need to see what you told me to turn decimal computer it doesn't matter, I also think the key is the customer so I have to do
Fourth master, fully understand a mistake, he sent me directly with a serial port communication monitoring data for the judgment, the actual situation where I have these data,
But I will turn the data is not the four, but more than fifty, I just put up a few to do a story, then I added in the other,

CodePudding user response:

I need to enter a string, the output is the hexadecimal ASCII array, is BYTE form, because of the need to sent via a serial port to the cache area

CodePudding user response:

reference 4 floor github_36000833 response:
began to make a test is not clear?

 
Using System;
Using System. Linq;
Using System. The Text;

Static class Program
{
The static void Main ()
{
Byte [] bytes1=Encoding. The ASCII. GetBytes (" # A 30 54 30 ");
Byte [] bytes2=new byte [] {0 x23, 0 x41, 0 x20, 0 x33, 0 x30, 0 x20, 0 x35, 0 x34, 0 x20, 0 x33, 0 x30};

Var sequence exactly equal=bytes1. SequenceEqual (bytes2);
Console. WriteLine (sequence exactly equal);//true
}
}



0 x23 and 35 is actually just don't do the same,

CodePudding user response:

The
Quote: reference 7 floor XBodhi. Response:

Quote: refer to 4th floor github_36000833 response:

To make a test is not clear?

You this array of data from where come of, you how I use a serial port communication monitoring results directly as a condition to deal with,
Byte [] bytes2=new byte [] {0 x23, 0 x41, 0 x20, 0 x33, 0 x30, 0 x20, 0 x35, 0 x34, 0 x20, 0 x33, 0 x30};

  •  Tags:  
  • C#
  • Related