Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
code indentation
Source Link
splattne
  • 104.4k
  • 54
  • 206
  • 250

I have a function to convert string to hex as this,

public static string ConvertToHex(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;  } 

Could you please help me write another string to Binary function based on my sample function?

public static string ConvertToBin(string asciiString)  {   string bin = "";   foreach (char c in asciiString)   {   int tmp = c;   bin += String.Format("{0:x2}", (uint)System.Convert.????(tmp.ToString()));   }   return bin;  } 

I have a function to convert string to hex as this,

public static string ConvertToHex(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;  } 

Could you please help me write another string to Binary function based on my sample function?

public static string ConvertToBin(string asciiString)  {   string bin = "";   foreach (char c in asciiString)   {   int tmp = c;   bin += String.Format("{0:x2}", (uint)System.Convert.????(tmp.ToString()));   }   return bin;  } 

I have a function to convert string to hex as this,

public static string ConvertToHex(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; } 

Could you please help me write another string to Binary function based on my sample function?

public static string ConvertToBin(string asciiString) { string bin = ""; foreach (char c in asciiString) { int tmp = c; bin += String.Format("{0:x2}", (uint)System.Convert.????(tmp.ToString())); } return bin; } 
Source Link
Nano HE
  • 2k
  • 7
  • 28
  • 41

String to Binary in C#

I have a function to convert string to hex as this,

public static string ConvertToHex(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; } 

Could you please help me write another string to Binary function based on my sample function?

public static string ConvertToBin(string asciiString) { string bin = ""; foreach (char c in asciiString) { int tmp = c; bin += String.Format("{0:x2}", (uint)System.Convert.????(tmp.ToString())); } return bin; }