-1

I have the following code:

string s =   "2563MNBJP89256666666685755854";
            Byte[] bytes = encoding.GetBytes(s);
            string hex = "";
            foreach (byte b in bytes)
            {
                int c=b;
                hex += String.Format("{0:x2}", (uint)System.Convert.ToUInt32(c.ToString()));
            }

It prints the hex values . How can I add it in a vector ob bytes like this?

new byte [0x32,0x35..]

In hex I have : 323536....and so on. The next step is to add then in a byte[] vector in the following format 0x32,0x35..and so on; How to do this?

THX

6
  • stackoverflow.com/questions/2575468/string-to-byte-array for the c++ part Commented May 18, 2011 at 7:46
  • Please read the FAQ on how to use this site... Commented May 18, 2011 at 8:17
  • do you mean an array of bytes? do you mean base64? do you mean another string of Hexidecimal numeral characheters? Commented May 18, 2011 at 8:20
  • yes an array og bytes that contains hexa values Commented May 18, 2011 at 8:21
  • Hm, could you clarify what you want to achieve? Commented May 18, 2011 at 8:52

4 Answers 4

1

Isn't bytes already the list of bytes you want?

Sign up to request clarification or add additional context in comments.

9 Comments

how to chech that? how to print the bytes values?
No it's not the same. The values are different:).
in s the results are: 50,53,54.. and in hex: 32,35,36 and so on
in s the results are in char! and in hex the results are in hexa values.
@daniel: Those are the same numbers. The first list is just represented in decimal while the second one is in hexadecimal.
|
0

C#: System.Text.Encoding.ASCII.GetBytes("test")

2 Comments

it's not the same thing. i've tested it:)
What is not the same? You get the byte values associated with each character.
0

For C# you could try

System.Text.ASCIIEncoding  encoding=new System.Text.ASCIIEncoding();
Byte[] bytes = encoding.GetBytes(strVar);//strVar is the string variable

1 Comment

is there a link for an converter in ASCII, string, bytes and others? I knoe there was one..but i just can;t find the link
0

in C# you can use Encoding.GetBytes Method

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.