十六进制中的MIDI文件

发布于 2025-01-24 12:22:57 字数 267 浏览 4 评论 0原文

我是编程的初学者 有没有办法读取其十六进制数字中的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我的影子我的梦 2025-01-31 12:22:57

让我告诉您一个秘密:您的计算机内部没有十六进制号。也没有十进制数字。计算机中的所有数字均以二进制存储。每当您在代码中写出95的小数号时,C ++的作用就是内部将其转换为二进制,并将其写入磁盘为1011111

因此,您要解决的问题需要重新介绍。您不想读取十六进制数字,而是要在代码中指定一个数字(通常像十进制一样)。

有多种指定十六进制号的方法。您可以使用计算器将数字从十字形转换为十进制,然后在您的代码中指定该小数号(例如十六进制号4D4 * 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 as 1011111.

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 is 4 * 16 + 13 == 77. So when you've read a number, you can then do if (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 write 77 in hex, you would write 0x4D. So once you've read the number from the file, you would do something like if (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 a 0, C++ thinks it is in octal. So be careful and don't prefix your decimal numbers with zeroes! Because 010 == 8, it's not 10 !

As to actually reading the data from the file, you do that using the fread() function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文