parent
8fd7554fda
commit
1c10ecf75b
@ -0,0 +1,38 @@ |
||||
using System; |
||||
using System.Globalization; |
||||
|
||||
namespace DevTips.Tips; |
||||
|
||||
class BaseConvertClient |
||||
{ |
||||
public static void Client() |
||||
{ |
||||
string strBase2 = "0000011011101010"; // 0x06EA |
||||
System.Console.WriteLine(strBase2); |
||||
int iBase10 = Convert.ToInt32(strBase2, 2); |
||||
System.Console.WriteLine($"iBase10: {iBase10}"); |
||||
|
||||
string strHex = Convert.ToString(iBase10, 16); |
||||
System.Console.WriteLine($"strHex: {strHex}"); |
||||
|
||||
string strHex2 = iBase10.ToString("X4"); |
||||
string strHex3 = string.Format("{0:X4}", iBase10); |
||||
System.Console.WriteLine($"strHex2: {strHex2}"); |
||||
System.Console.WriteLine($"strHex3: {strHex3}"); |
||||
|
||||
int iBase10_2 = Convert.ToInt32(strHex3, 16); |
||||
System.Console.WriteLine($"iBase10_2: {iBase10_2}"); |
||||
|
||||
string strBase2_2 = Convert.ToString(iBase10, 2); |
||||
System.Console.WriteLine($"strBase2_2: {strBase2_2}"); |
||||
|
||||
string hexStr = "5A"; |
||||
System.Console.WriteLine(hexStr); |
||||
byte b1 = Convert.ToByte(hexStr, 16); |
||||
System.Console.WriteLine($"b1: {b1:X}"); |
||||
|
||||
string hexStr2 = "9E"; |
||||
byte b2 = byte.Parse(hexStr2, NumberStyles.HexNumber); |
||||
System.Console.WriteLine($"b2: {b2:X}"); |
||||
} |
||||
} |
@ -0,0 +1,32 @@ |
||||
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); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue