Hi,
Try this-
string str = "Hello";
byte []arr = System.Text.Encoding.ASCII.GetBytes(str);
Or
string result = string.Empty;
foreach(char ch in yourString)
{
result += Convert.ToString((int)ch,2);
}
OUTPUT-
this will translate "Hello" to 10010001100101110110011011001101111
String to Hex and vise versa
public string ConvertStringToHex(string asciiString)
{
string hex = "";
foreach (char c in asciiString)
{
int tmp = c;
hex += String.Format("{0:x2}", (uint)System.Convert.ToUInt32(tmp.ToString()));
}
return hex;
}
public string ConvertHexToString(string HexValue)
{
string StrValue = "";
while (HexValue.Length > 0)
{
StrValue += System.Convert.ToChar(System.Convert.ToUInt32(HexValue.Substring(0, 2), 16)).ToString();
HexValue = HexValue.Substring(2, HexValue.Length - 2);
}
return StrValue;
}