十六进制中的MIDI文件
我是编程的初学者 有没有办法读取其十六进制数字中的MIDI文件?
我搜索了Internet,MIDI文件是由标头组成的,其内容在十六进制数字中 4d 54 68 64 0a ....
那么,从MIDI文件中提取十六进制编号的最佳方法是什么?如果有一个C ++库可以执行此操作? (我想用C ++语言编写该程序)
对于上下文,我想将这些十六进制编号放入数组中,然后替换一些十六进制编号(当然是根据MIDI文件格式,因此MIDI文件不会损坏)并将其保存回MIDI文件。喜欢做某种隐肌
I am a beginner in programming
Is there a way to read a midi file in its hex numbers?
I searched the internet that midi files are composed of headers and their contents are in hex numbers like
4D 54 68 64 0A ....
So, what is the best way to extract those hex numbers from a midi file? If there is a C++ library to do this? (I want to write the program in C++ language)
For context, I want to put these hex numbers into an array and replace some of those hex numbers (of course according to the midi file format, so the midi file isn't corrupted) and save it back into a midi file. Like doing some kind of steganography
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
让我告诉您一个秘密:您的计算机内部没有十六进制号。也没有十进制数字。计算机中的所有数字均以二进制存储。每当您在代码中写出
95
的小数号时,C ++的作用就是内部将其转换为二进制,并将其写入磁盘为1011111
。因此,您要解决的问题需要重新介绍。您不想读取十六进制数字,而是要在代码中指定一个数字(通常像十进制一样)。
有多种指定十六进制号的方法。您可以使用计算器将数字从十字形转换为十进制,然后在您的代码中指定该小数号(例如十六进制号
4D
是4 * 16 + 16 + 13 == 77
因此。但是,由于十进制和十六进制中的编写数字在编程中是一件常见的事情,因此C ++实际上具有编写十六进制数字的方式。您在开始时用
0x
编写十六进制号码。因此,要在十六进制中编写77
,您将编写0x4d
。因此,一旦您从文件中读取了数字,就可以执行之类的事情,如果(thenumber == 0x4d)...
。您可以在C ++中指定数字的其他基础。二进制数字有
0b
(因此,要准确指定数字在磁盘上的方式),并且如果仅以0
开始,则C ++认为它在八元。因此,请小心,不要将小数号以零前缀!因为010 == 8
,它不是10
!至于实际读取文件中的数据,您可以使用
fread()
函数来完成此操作。Let me tell you a secret: There are no hex numbers inside your computer. There are also no decimal numbers. All numbers in your computer are stored as binary. Whenever you write a decimal number like
95
in your code, what C++ does is convert it into binary internally and write it to disk as1011111
.As such, the problem you're trying to solve needs to be re-phrased. You do not want to read hex numbers, but rather, you want to specify a number as hex in your code (instead of as decimal like usually).
There are various ways to specify a hex number. You could use a calculator to convert the number from hex to decimal, then specify that decimal number in your code (e.g. hex number
4D
is4 * 16 + 13 == 77
. So when you've read a number, you can then doif (theNumber == 77) ...
).However, since writing numbers in decimal and hexadecimal is a common thing in programming, C++ actually has a way built in to write hexadecimal numbers. You write your hexadecimal number with a
0x
at the start. So to write77
in hex, you would write0x4D
. So once you've read the number from the file, you would do something likeif (theNumber == 0x4D) ...
.There are other bases in which you can specify a number in C++. There is
0b
for binary numbers (so to specify the number exactly how it will be on disk), and if a number starts with just a0
, C++ thinks it is in octal. So be careful and don't prefix your decimal numbers with zeroes! Because010 == 8
, it's not10
!As to actually reading the data from the file, you do that using the
fread()
function.