Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here is my code

C#
int Appno= 0X0A0A0A0A;
byte[] Apps_Num_bytes = ConvertInt32ToByteArray((int)Appsno);


i want to convert this to string as i want the output comes like "0A0A0A0A"
or direct from int Appno to string like "0A0A0A0A"

please help me

thanks
bipul pandey
Posted
Updated 14-Mar-14 3:07am
v2
Comments
Rob Philpott 14-Mar-14 9:29am    
It's not clear what you mean. Do you want a four character with each character set to 10 (0x0a) or do you want and 8 character string literal "0A0A0A0A"?

When it comes to string representations, the Encoding[^] is important. It tells the computer whether you want ASCII, UTF8, or whatever. Use it like this:
C#
string stringRepresentation = System.Text.Encoding.ASCII.GetString(Apps_Num_bytes);
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 14-Mar-14 9:32am    
Correct, a 5.
—SA
int Appno = 0X0A0A0A0A;
string s1 = BitConverter.ToString(BitConverter.GetBytes(Appno)).Replace("-","");


-----------Output------------
0A0A0A0A
 
Share this answer
 
Comments
bipul_pandey 17-Mar-14 1:08am    
hello
Soham

this solution change the byte ordar like if the data is

x= 0x0004eb9c;
string s1 = BitConverter.ToString(BitConverter.GetBytes(x)).Replace("-","");
string s1 = "9CEB0400" ;

like this ...
try this.........

C#
int Appno = 0x0004EB9C;
//int Appno = 0X0A0A0A0A;
string final = "";

string s = BitConverter.ToString(BitConverter.GetBytes(Appno));

string[] arr = s.Split('-');

for (int i = 0; i < arr.Length; i++)
{
    char[] charArray = arr[i].ToCharArray();
    Array.Reverse(charArray);
    final = final + new string(charArray);
}

char[] charArray2 = final.ToCharArray();
Array.Reverse(charArray2);
final= new string(charArray2);
MessageBox.Show(final);


your desire output in final string variable....
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900