将十六进制写入二进制文件 [英] writing hex to a binary file

查看:113
本文介绍了将十六进制写入二进制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将十六进制写入二进制文件,即''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.net (Caryn Graves)在comp.lang.c中写了


On 22 Jan 2004 15:24:03 -0800, ca***@holonet.net (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

主页: http://JK-Technology.Com

常见问题解答

comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html

comp.lang.c ++ http://www.parashift.com/c++-faq-lite/

alt.comp.lang.learn.c-c ++
http://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: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html


这篇关于将十六进制写入二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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