将十六进制写入二进制文件

编程入门 行业动态 更新时间:2024-10-27 08:39:11
本文介绍了将十六进制写入二进制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要将十六进制写入二进制文件,即''00A8''(十进制168) 输出为2字节,'FE''(十进制254)输出为1字节等等 建议??

I need to write hex into a binary file, i.e., ''00A8'' (decimal 168) output as 2 bytes, ''FE'' (decimal 254) output as 1 byte, etc. Suggestions??

推荐答案

2004年1月22日星期四, Caryn Graves写道: On Thu, 22 Jan 2004, Caryn Graves wrote: 我需要将十六进制写入二进制文件,即''00A8''(十进制168)输出为2个字节,''FE' '(十进制254)输出为1字节等。建议?? I need to write hex into a binary file, i.e., ''00A8'' (decimal 168) output as 2 bytes, ''FE'' (decimal 254) output as 1 byte, etc. Suggestions??

不要在组之间交叉发布不相关的语言,除非 你准备好了很多无用的信息,这些信息并不适用于你选择的语言。例如,这就是你在C中用它做的事情,但首选的C ++方式略有不同 (例如,至少使用< cstdio>,如果不是一些聪明的< iostream> 操纵)。 关于此子线程的后续设置为comp.lang.c。 #include< stdio.h> int main(无效) { FILE * myfile = fopen(" ; filename"," wb"); putc(0x00,myfile); putc(0xA8,myfile); putc( 0xFE,myfile); fclose(myfile); 返回0; } HTH, -Arthur

Don''t cross-post between groups for unrelated languages unless you''re prepared for a lot of useless information that doesn''t apply to your language of choice. For instance, this is how you''d do it in C, but the preferred C++ way is subtly different (e.g., at least using <cstdio>, if not some clever <iostream> manipulation). Followups set to comp.lang.c on this subthread. #include <stdio.h> int main(void) { FILE *myfile = fopen("filename", "wb"); putc(0x00, myfile); putc(0xA8, myfile); putc(0xFE, myfile); fclose(myfile); return 0; } HTH, -Arthur

Caryn Graves写道: Caryn Graves wrote: 我需要将hex写入二进制文件,即''00A8''(十进制168)输出为2个字节,''FE''(十进制254)输出为1个字节等。 I need to write hex into a binary file, i.e., ''00A8'' (decimal 168) output as 2 bytes, ''FE'' (decimal 254) output as 1 byte, etc.

你很困惑。 你想写*二进制*。 使用ostream me mber函数用C ++编写,用fwrite编写。

You are confused. You want to write *binary*. Use ostream member function write in C++ and fwrite in C.

2004年1月22日15:24:03 -0800, ca *** @ holonet (Caryn Graves)在comp.lang.c中写了 : On 22 Jan 2004 15:24:03 -0800, ca***@holonet (Caryn Graves) wrote in comp.lang.c: 我需要将十六进制写入二进制文件,即''00A8''(十进制168)输出为2字节,''FE''(十进制254)输出为1字节等。建议?? I need to write hex into a binary file, i.e., ''00A8'' (decimal 168) output as 2 bytes, ''FE'' (decimal 254) output as 1 byte, etc. Suggestions??

建议1:不要在comp.lang.c和comp.lang.c ++之间交叉发布。 建议2:澄清你的问题。十六进制是 文本的概念,而不是纯二进制文件。 - Jack Klein 主页: JK-Technology.Com 常见问题解答 comp.lang.c www.eskimo/~scs/C-faq/top.html comp.lang.c ++ www.parashift/c++-faq-lite/ altp.lang.learn.c-c ++ www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html

Suggestion 1: Don''t cross-post between comp.lang.c and comp.lang.c++. Suggestion 2: Clarify your question. Hexadecimal is a concept of text, not of pure binary files. -- Jack Klein Home: JK-Technology.Com FAQs for comp.lang.c www.eskimo/~scs/C-faq/top.html comp.lang.c++ www.parashift/c++-faq-lite/ altp.lang.learn.c-c++ www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html

更多推荐

将十六进制写入二进制文件

本文发布于:2023-10-27 18:32:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1534191.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:二进制文件   将十六进制

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!