ascii-hex conversion in verilog
我正在寻找一个 Verilog 函数来将我的 ASCII 输入字符串转换为十六进制输出。我不确定我是否可以在 C 中做到这一点并与 Verilog 一起使用。到目前为止,我能够使用以下命令将输入??的 ASCII 字符串打印为十六进制值:
1
2 3 4 5 |
有没有办法将输出保存在文本/csv 文件中,并使其可供我的 verilog 代码片段访问?
或者请让我知道 Verilog 本身是否有更简单的方法?
- 完全不相关,但您应该避免在每次循环迭代时调用 strlen() 。 strlen() 不是 O(1) 操作。你应该改为 size_t max = strlen(callid); for(c = 0; c < max; c++)
- @Chris:您的建议有所帮助,但仍然很愚蠢。而是将循环条件从 c<strlen(callid) 更改为简单的 callid 并完全避免调用 strlen。
- 您是否尝试使用 ASCII 字符驱动 verilog 总线?
要输出到文本文件,你可以这样做:
1
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
static int string_to_hex_file(const char *filename, const char *string)
{ FILE *out; const char *s; if((out = fopen(filename,“w”)) == NULL) fprintf(out,“”%s“,”, string); fclose(out); |
string ==”this is a test”:
的示例输出
1
|
“this is a test”, 0x74, 0x68, 0x69, 0x73, 0x20, 0x69, 0x73, 0x20, 0x61, 0x20, 0x74, 0x65, 0x73, 0x74
|
当然可以改进错误检查,您可能需要调整输出格式以满足您的需要。
来源:https://www.codenong.com/4131160/