Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Convert file

Posted on 1998-11-10
6
Medium Priority
?
227 Views
Last Modified: 2010-04-15
hai..

can we convert the file which contains hex / character / base64 format into text format that can be read. Assume that i have this line of hex formated:

00 02 FF 0F 47 5F

after convert i got this text "Hello". Can we do that?

Thanks,

Suhaimi
0
Comment
Question by:suhai
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1254131
Are you sure that
00 02 FF 0F 47 5F
converts into "Hello"?  How did you convert it?
what format is this supposed to be?  hex, or character, or base64?
0
 
LVL 1

Expert Comment

by:Grailman
ID: 1254132
"can we convert the file ... into text format that can be read"
I don't understand since this is how we read text files. Opening a file with the binary values 48 45 4C 4C 4F will give the text "HELLO". Do you mean you want to open a text file with the text "48 45 4C 4C 4F" and have it convert the three chars "48 " into one char "H"?

0
 

Author Comment

by:suhai
ID: 1254133
Yes grailman,  you've got my point. Do you have any program converter or some sample program?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 84

Expert Comment

by:ozo
ID: 1254134
while( scanf("%2x",&c)>0 ){ putchar(c); }
0
 
LVL 1

Accepted Solution

by:
Grailman earned 30 total points
ID: 1254135
void Convert(char* pStr, int StrSize)
{
  // pStr is a pointer to text string to be converted
  // and should be checked before calling this to
  // make sure all chars are '0-9' 'a-f' A-F' space <CR> or <LF>

  char ch;
  char Byte;
  int NibbleCount = 0;

  for(int i = 0; i < StrSize; i++)
  {
    ch = pStr;

    // make sure we have a char
    if(ch != 0x0A && ch != 0x0D && ch != 0x20)
    {
      if            (ch >= '0' && ch <= '9')      ch -= '0';
      else if      (ch >= 'a' && ch <= 'f')      ch -= ('a' - 10);
      else if      (ch >= 'A' && ch <= 'F')      ch -= ('A' - 10);

      if(!(NibbleCount % 2))                  // Set lower nibble
      {
        Byte = (ch << 4);
      }
      else                                          // Set upper nibble
      {
        Byte += ch;
        printf("%c", Byte);
      }
      NibbleCount++;                        // increment for each nibble
    }
    else
      printf("%c",ch);                        // print <CR><LF> or Space

    pStr++;
  }
}

0
 

Author Comment

by:suhai
ID: 1254136
Thanks.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question