Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] Converting a byte array in a string in C#

Status
Not open for further replies.

dipk11

Junior Member level 2
Joined
Jul 27, 2017
Messages
23
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
245
Hi all,
I have a byte array byte[] dStream = new byte[6];
the contents are as follows
{0x7C 0x00 0x7A 0x10 0x00 0x00}
When I check the array values in watch window, I can see them converted into decimal and not hex.
I want to generate a String Data= "7c,00,7a,10,00,00"

How can I do this in my c#? Kindly help

- - - Updated - - -

Hi, I wrote the following code. but I am getting the string in decimal. How do I get each value in hex?


Code C# - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
String cArgument = "";
for (int j = 0; j < 12; j++)
{
if (j == 11)
{
cArgument = cArgument + dStream[j];
}
else 
{
cArgument = cArgument + dStream[j] + ",";
}
}



output:
"124,0,122,16,0,0,4,0,0,2,123,48"

I want it to be "7C,00,7A,10,00,00,04,00,00,02,7B,30"

Kindly tell me the changes in the present code...

- - - Updated - - -

Hey I did it like this.

Code C# - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
//converting to hex value
string[] datastring = new string[dStream.Length];
for (int i = 0; i < dStream.Length; i++)
{
datastring[i] = dStream[i].ToString("X");
}
 
String cArgument = "";
for (int j = 0; j < 24; j++)
{
if (j == 23)
{
cArgument = cArgument + datastring[j];
}
else 
{
cArgument = cArgument + datastring[j] + ",";
}
}



But these have too many lines of codes...But works perfectly. And gives me 24bit data.
 
Last edited by a moderator:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top