static void Main(string[] args)
{
{
// Bytes to int
byte[] bytes = { 0, 0, 25, 25 };
// 이 컴퓨터 아키텍처에서 데이터가 저장되는 바이트 순서("endian")를 나타냅니다.
// 이 아키텍처가 little-endian이면 true이고, big endian이면 false입니다.
if (BitConverter.IsLittleEndian)
Array.Reverse(bytes);
int i = BitConverter.ToInt32(bytes, 0);
Console.WriteLine("int: {0}", i);
// Output: int: 6425
}
{
// int to bytes
byte[] bytes = BitConverter.GetBytes(123456);
Console.WriteLine("byte array: " + BitConverter.ToString(bytes));
// Output: byte array: 40-E2-01-00
}
}
반응형
'개발 > C#' 카테고리의 다른 글
C# parse xml pretty string (0) | 2022.01.20 |
---|---|
C# string to int 확장형 (0) | 2022.01.11 |
C# 클라이언트 Browser 정보얻기 (0) | 2022.01.07 |
C# 로컬IP(서버IP)정보 조회 (0) | 2022.01.06 |
C# 파일사이즈 Long -> String 변환 (0) | 2022.01.06 |
댓글