i making a program with CSharp Language. But, I have a big problem. I'm making a program that reading a file by a hex and converting hex to string. but, i can't get string perfectly. The blue one is a hex code that i want to converting to string. this is hex code...
but i cant get only 59fd50a62fb9a8ef, not including a file extension.
i want to get perfect string like 59fd50a62f9a8ef.bmp
How can i do ?
This is a source code that converting a hex to string.
string toString(string hexString)
{
var bytes = new byte[hexString.Length / 2];
for (var i = 0; i < bytes.Length; i++)
{
bytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
}
return Encoding.Unicode.GetString(bytes);
}
You cannot get the file extension from the bytes you highlighted. As far as I can tell they contain a hexadecimal filename, which you have extracted successfully already, an end of string character (two zeroes), the start of a bitmap ( BM
) and the length of the bitmap ( 36 10 00 00
in little endian ). So, to get a filename you just have to append .bmp
to your hexadecimal string.
If, however, the image is not always a bitmap, then you should create a function that deduces the filetype from the bytes after the end of string character.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.