string myString = ""; int myInt = 1; myString = myInt.ToString().PadLeft(8, '0'); //myString will be 00000001 myString = myInt.ToString().PadRight(8, '0'); //myString will be 10000000MSDN Pad Left
MSDN Pad Right
string myString = ""; int myInt = 1; myString = myInt.ToString().PadLeft(8, '0'); //myString will be 00000001 myString = myInt.ToString().PadRight(8, '0'); //myString will be 10000000MSDN Pad Left
public string ConvertAsciiToHex(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; }Convert Hex to Ascii method
public string ConvertHextoAscii(string HexString) { string asciiString = ""; for (int i = 0; i < HexString.Length; i += 2) { if (HexString.Length >= i + 2) { String hs = HexString.Substring(i, 2); asciiString = asciiString + System.Convert.ToChar(System.Convert.ToUInt32(HexString.Substring(i, 2), 16)).ToString(); } } return asciiString; }
public static string ReverseString(string s) { char[] charArray = s.ToCharArray(); Array.Reverse(charArray); return new string(charArray); }
int DecimalVal = 256; string BinaryVal = Convert.ToString(DecimalVal, 2);Binary to Decimal conversion as below:
string BinaryVal = "01001101"; string DecimalVal = Convert.ToInt32(BinaryVal, 2).ToString();
string date = DateTimePicker1.Value.ToString("yyyy-MM-dd");
int DecimalVal = Convert.ToInt32(HexVal, 16);Convert Decimal to Hex as below;
string HexVal = DecimalVal .ToString("X");
DateTime DT = DateTime.ParseExact("20121207015640","yyyyMMddHHmmss",null);For more info MSDN DateTime.ParseExact