现在的位置: 首页 > 综合 > 正文

十六进制的TXT文件怎么以十六进制读出来?

2012年06月05日 ⁄ 综合 ⁄ 共 744字 ⁄ 字号 评论关闭

 txt中的内容是4E6574776F726B205365637572697479
但是运行后的不是txt中的十六进制内容,

#include<iostream.h>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
typedef unsigned char       BYTE;
typedef unsigned int        DWORD;          /* 32 bit data type */

BYTE hex_value(BYTE value)
{
 return ( ((value & 0x7f) >= 'A') ? (value - 7) : value)   & 0x0f;
}

void compress(BYTE  *dest, BYTE  *source, DWORD pair)
{
 while (pair)
 {
  pair--;
  *dest = (hex_value(*source++) << 4);
  *dest++ += hex_value(*source++);
 }
}
int main()
{
 FILE *fp;
 unsigned char buffer[50];
 unsigned char buf2[25];
 
 if((fp=fopen("f1.txt","ab+"))==NULL)
 {
  cout<<"Cannot open the des_plain.txt"<<endl;
  exit(0);
 }
 fread(buffer,32,1,fp);
 compress(buf2,buffer,16);
 for(int i=0;i<16;i++)
 {
  printf("%02x",buf2[i]);

 }
 
 
 fclose(fp);
 
 return 0;
}

read_txt.cpp E:\VCtest

抱歉!评论已关闭.