如何获取任何文件的二进制形式并以二进制形式和原始文件格式存储? [英] How to get the binary form of any file and to store it in its binary form and in its original file format ?

查看:451
本文介绍了如何获取任何文件的二进制形式并以二进制形式和原始文件格式存储?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即如何将任何文件(如图像,视频,PDF等)转换为二进制形式(如十六进制编辑器所做的那样)。然后将二进制表单数组存储到文件中(文本文件格式为1s和0s)。从文件中检索二进制数;要么通过内置算法修改,要么只是保存回其原始文件格式。如果可能的话,是否有代码来获取文件名称,如果文件的名称已知。



我尝试过:



尝试ASCII等效转换,但无法转换图像文件的所有8位二进制值。

解决方案

从文件扩展名中获取文件类型是很常见的。其他一切都在猜测。检查扩展开关后进一步处理。记录文件数据类型。使用codeproject搜索框查找示例。



要将文件转换为十六进制数据,必须读取文件二进制数据,然后将每个字节转换为十六进制值。反向转换是相反的过程。



并非每个ASCII都是文本字符。在原始版本中,ASCII只有7位(而不是8位,这是一个字节)。



一些示例。后转换是对每个字节字符使用 strol 函数并将其写入diek。

引用:

如何将图像,视频,pdf等文件转换为二进制形式

文件的二进制形式是它的存储方式。

编辑器的十六进制模式只是一个允许你看到不可打印字符的演示文稿。



如果要对文件进行更改,程序可以直接在原始文件中进行更改。对于一个程序,处理二进制文件并不比使用Hex副本更复杂,实际上Hex副本没有优势,唯一的区别是你需要更多的步骤来转换文件。


i.e how to convert any file like images, video , pdf ,etc.. to its binary form(like what hex-editor do). Then store the binary form array into a file(text file in the form of 1s and 0s). Retrieve the binary numbers from the file; either to modify by inbuilt algorithms or just to save back to its original file format.If possible , is there a code to get the file format if the name of the file is known.

What I have tried:

Tried ASCII equivalent conversion but cannot convert all the 8-bit binary values of an image file.

解决方案

It is usuak to get the file type out of its extension. Everything else is guessing. After checking the extension switch for the further processing. File data types are documented. Use the codeproject search box to find examples.

To convert a file into hexadecimal data, you must read the file a binary data and than convert each byte into a hex value. The back conversion is the reverse process.

Not every ASCII is a textual character. In the original version ASCII had only seven bits (and not 8 bits which are a byte).

Some example for reading binary data. The back conversion is to use the strol function for every single byte character and write it to diek.


Quote:

how to convert any file like images, video , pdf ,etc.. to its binary form

The binary form of a file is how it is stored.
Editor's Hex-mode is just a presentation that allow you to see non printable characters.

If you want to do changes in a file a program can do it directly in the original file. For a program, working on a binary file is not more complicated than working on a "Hex" copy, in fact the "Hex" copy offer no advantage, the only difference is that you need more steps to convert the file.


这篇关于如何获取任何文件的二进制形式并以二进制形式和原始文件格式存储?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆