在 C# 中获取十六进制文件大小
Get file size as hex in C#
我正在尝试将文件大小从文件转换为十六进制代码,但它给了我一个错误.
到目前为止我拥有的代码:
public static string DecToHex(int decValue)
{
return string.Format("{0:x}", decValue);
}
private void button1_Click(object sender, EventArgs e)
{
DirectoryInfo dinfo = new DirectoryInfo(@"C:UsersAdminDesktop10 23files");
FileInfo[] Files = dinfo.GetFiles("*.xml");
foreach (FileInfo file in Files)
{
listBox1.Items.Add(file.Name);
}
}
private void button2_Click(object sender, EventArgs e)
{
DirectoryInfo dinfo = new DirectoryInfo(@"C:UsersAdminDesktop10 23files");
FileInfo[] Files = dinfo.GetFiles("*.xml");
foreach (FileInfo file in Files)
{
listBox2.Items.Add(DecToHex(file.Length));
}
}
错误是"..无法从"long"转换为"int"。也许有人知道一种更好的方法 将文件大小显示为十六进制 .
我在 c++ 中有这段代码
if(m_bAlgorithm[HASHID_SIZE_32])
{
sizehash32_end(&m_uSizeHash32);
printf(SZ_SIZEHASH_32);
printf(SZ_HASHPRE);
printf("%08X", m_uSizeHash32);
printf(CPS_NEWLINE);
}
为什么不将DecToHex
方法更改为接受 long。
FileInfo.Length
返回一个长整型,您可以使用长整型作为string.Format
的参数。
public static string DecToHex(long decValue)
{
return string.Format("{0:x}", decValue);
}
相关文章:
- 将字符指针十六进制转换为字符串并保存在文本文件C++中
- 读取文件中所有可能的十六进制 16 字节序列并打印每个序列
- 在 c++ 中从文本文件中读取两个十六进制值
- 正在读取十六进制文件C++
- 如何在C 中的Little Endian中读取来自二进制文件的单独的十六进制字符
- C++如何从文件中读取十六进制字节并将其存储为指针
- 计算 RSA 并以十六进制格式保存到文件
- 需要在 c++ 中以十六进制格式将字符串写入文件
- 为什么 .out 文件是十六进制而不是二进制
- 在不同的机器上编译的是Arduino ESP8266项目的不同十六进制文件
- 在C/C++中将十六进制数组作为字符串写入文件
- 将 OpenCV MAT 保存到 TXT 文件作为不带分隔符的十六进制值
- 如何使用C预处理器生成可变大小(取决于操作系统)的十六进制文字
- 从 bin 文件 -c++ 中读取十六进制数字为每个字符 2 位数字
- 十六进制数组 cout 到文本文件失败
- C++在读取和写入十六进制文件时出现问题
- 在 C# 中获取十六进制文件大小
- 如何将十六进制文件转换为二进制文件
- 读取十六进制文件会产生错误的输出(跳过一些十六进制值)
- 将十六进制文件读取到二进制缓冲区的文件流