You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
dotnetDevTips/DevTips/DevTips/Tips/BinaryStringClient.cs

32 lines
897 B

using System;
using System.Text;
namespace DevTips.Tips
{
class BinaryStringClient
{
public static void Client()
{
string input = "iPhone 가격은?";
System.Console.WriteLine(input);
byte[] bytes = UnicodeEncoding.Unicode.GetBytes(input);
System.Console.WriteLine($"Bytes length: {bytes.Length}");
string binaryString = string.Empty;
string hexString = string.Empty;
foreach (byte b in bytes)
{
string s = Convert.ToString(b, 2);
binaryString += s.PadLeft(8, '0');
binaryString += " ";
hexString += b.ToString("X2");
hexString += " ";
}
System.Console.WriteLine(binaryString);
System.Console.WriteLine(hexString);
}
}
}