16 진수 형식의 문자열을 16 진수 바이트 배열로 변환하는 방법에 대한 많은 답변을 찾을 수 있지만 텍스트가있는 문자열을 바이트 배열로 변환하는 방법을 알고 싶습니다.
아이디어를 제공하기 위해 다음은 16 진수 형식을 사용하여 텍스트를 바이트 배열로 변환하는 코드입니다.
FileStream fs = File.OpenRead(filePath);
byte[] fileInBytes;
using (BinaryReader br = new BinaryReader(fs))
{
List<byte> bytesList = new List<byte>();
while (fs.Position < fs.Length)
{
bytesList.Add(byte.Parse(Encoding.ASCII.GetString(br.ReadBytes(2)),
NumberStyles.HexNumber));
}
fileInBytes = bytesList.ToArray();
}
return fileInBytes;
문자열을 사용하여 어떻게 할 수 있습니까?
public static byte[] getBytesFromString(String str)
{
//What now?
}
기본적으로 16 자의 문자열을 입력하면 8 바이트의 바이트 배열을 반환하고 싶습니다.
되돌릴 바이트 수는 확실하지 않지만 아래를 참조하십시오.
public static byte[] getBytesFromString(String str)
{
return Encoding.ASCII.GetBytes(str)
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다