[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Converting HEX  strings to ASCII strings

Posted on 2000-04-13
13
Medium Priority
?
357 Views
Last Modified: 2010-04-04
I need to find out how to convert Hex strings to Ascii Strings

Example

AssignFile(F, 'Love.midi');
  Rewrite(F);
  Writeln(F , ':4D 54 68 64 00 00 00 '  );    // This is the Hex
                                              // String
  CloseFile(F);      { Close file, save changes }

and after when you load the created file 'love.midi' through a txt editor it must be in ascii format and not in hex code (hex ascii code)

The WriteIn(F , ':4D 54 68 00 00 00' );
on a midi file using a text editor to view the written string is written as

4D 54 68 00 00 00

instead of the preferred way that I want which is

MThd...

Please reply

Ben
0
Comment
Question by:Ben_iti
[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
  • 4
  • 3
  • 3
  • +3
13 Comments
 
LVL 7

Accepted Solution

by:
Motaz earned 400 total points
ID: 2711614
Use this instead:

AssignFile(F, 'Love.midi');
  Rewrite(F);
  Writeln(F , $4D, $54, $68, $64, $00, $00, $00);
  CloseFile(F); { Close file, save changes }

Motaz
0
 

Author Comment

by:Ben_iti
ID: 2711620
No Comments

Have a bogus day
0
 

Author Comment

by:Ben_iti
ID: 2711662
No im sorry Motaz
That did not work

It came up viewed using a text editor as this

7784104100000

and not like this

Mthd...

Keep trying, for a minute there
I thought you actually had the answer

Thanks
Ben
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 7

Expert Comment

by:Motaz
ID: 2711692
I didn't understand what did you want exactly.

Any whay you may use Typed file instead:

var
  f: file of byte;
  b: Byte;
begin
  AssignFile(F, 'Love.midi');
  Rewrite(F);
  B:= $4D;
  Write(F, B);
  B:= $54;
  Write(F, B);
  ...
  CloseFile(F);
end;
0
 
LVL 6

Expert Comment

by:Jaymol
ID: 2711703
You need to change one line of Motaz's code to this....

Writeln(F , #$4D, #$54, #$68, #$64, #$00, #$00, #$00);

Motaz still deserves the points though.

John.
0
 
LVL 6

Expert Comment

by:Jaymol
ID: 2711707
Oh yeah, it will actually show MTHD not Mthd  (All uppercase character values.)

John.
0
 
LVL 6

Expert Comment

by:Jaymol
ID: 2711712
Ignore that stupid comment.

John.
0
 
LVL 2

Expert Comment

by:mullet_attack
ID: 2711746
Perhaps the best way would be to use
"Format", eg

Format('%2.2x',[$4D])

This will write 2 hex digits, left padded if necessary.

or Format('3.3d',[$4D])

This will write 3 decimal digits, left padded if necessary.

I'm not quite sure which one you want.

You could use a loop and "copy" to parse the string of ascii text and write it your file.
0
 
LVL 6

Expert Comment

by:Jaymol
ID: 2711755
Huh?????

Just use the original code posted by Motaz (the nicest looking) and alter in the way I showed.

It's the easiest and nicest to look at.

Like I said, Motaz got it right, apart from that one little oversight.

John.
0
 
LVL 2

Expert Comment

by:craig_capel
ID: 2711809

header:='YCHT'+chr(0)+chr(0)+chr(0)+chr(1)+chr(0) +chr(0)+chr(0)+chr(0)+chr(1);
  chr(length(username))+chr(length(cookie))+chr(4);
for l:=1 to length(header) do
  begin
  mychar:=header[l];
    buffer[l]:=mychar;
  end;
for l:=length(header) to length(header+username) do
  begin
    buffer[l]:=username[l];
  end;

{

ycht   +    ver +  type +   size +    name  + del1 +  cookie

where,
ycht     = YCHT
ver      = 0010
login    = 0001
size     = len(name)  + len(cookie) + len(del1)
name     = username
cookie   = cookie
del1     = 0x01

}


I'm having a problem kinda the same.... this is whats needed to do, but i bet if this is solved then, his problem is too..... but with this you have a multiple of vars, including size the name.....

header:='YCHT'+chr(0)+chr(0)+chr(0)+chr(1)+chr(0) +chr(0)+chr(0)+chr(0)+chr(1);  <<Is this the way to go?.... for you love.midi thing?.. or is there no easy solution to this....

0
 
LVL 2

Expert Comment

by:florisb
ID: 2713063
not what you ask, fast post. 'move' is related to..
Floris.

unit Unit1; interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type TStr25 = string[25];
     TStr4  = string[4];
     TStr9  = string[9];
     Tstr8 = string[8];
     Tstr1 = string[1];

Type
  PEmp1St = ^TEmp1St;
  TEmp1St = Record
                ANaam     : TStr25;  
                Straat    : TStr25;
                Plaats    : TStr25;
  end;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
Var
  a   : SmallInt;
  Mw1 : TEmp1St;
  Mw2 : TEmp1St;
  T : Array[1..2000] Of Byte;
  u,v : widestring;
  w : byte;
Begin
  //init Mw1, Mw2
  FillChar( Mw1, SizeOf( TEmp1St), 0);
  FillChar( Mw2, SizeOf( TEmp1St), 0);

  //values Mw1
  Mw1.ANaam := 'floris';
  Mw1.Straat := 'jaja';
  Mw1.Plaats := 'Adam';

  //Mw1 to array
  Move( Mw1, T, SizeOf( TEmp1St));

  //now convert T to a widestring.
  u := '';
  for a := 1 to 2000 do
    begin
    u := u + char(T[a]);
    end;

  //now convert widestring again to T
  for a := 1 to 2000 do
    begin
    T[a] := byte(u[a]);
    end;

  // move T to Mw2 and show some fields.
  Move( T, Mw2, SizeOf( TEmp1St));
  showMessage(Mw2.Anaam+';'+Mw2.Straat+';'+Mw2.plaats);
end;
end.
0
 

Author Comment

by:Ben_iti
ID: 2714929
Thankyou Motaz

You were the first to reply to my question, the funniest thing
you answered my email 30 seconds later
That only tells me that your a pro.

I thankyou for your answer and for your quick reply.

The 100 points go to you.

I would also like to thank Jaymol (John)
who also replied to my email saying for me to add those nifty '#'s to Motaz code
I Thankyou both

Ben Iti


0
 
LVL 7

Expert Comment

by:Motaz
ID: 2718599
Welcome any time Ben Iti, I'm happy that I was helped you.

Motaz
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

650 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