Topic: convert ASCII representation of Hex into HEX (1 of 5), Read 63 times
Conf: VEDIT Macro Language Support
From: Graham Walker
Date: Friday, September 01, 2000 12:11 PM

I have recently started to use Vedit.
I am trying to convert an ASCII representation of a Hex character in to the Hex character itself. Has any one any suggestions on how I can do this in the Macro lang.

e.g. turn 1B into a single Hex digit in this case an escape.

 


Topic: Re: convert ASCII representation of Hex into HEX (2 of 5), Read 60 times
Conf: VEDIT Macro Language Support
From: Christian Ziemski
Date: Friday, September 01, 2000 01:13 PM


>I am trying to convert an ASCII representation of a Hex character in to =the Hex character itself.

// Converting an ASCII 2-digit hex value into it's "real" hex value
//
// Cursor positioned on the first byte of the hex value

Ins_Text("0x")
Char(-2)
#11=Num_Eval(SUPPRESS)
Del_Char(4)
Ins_Char(#11)


Christian

 


Topic: Re: convert ASCII representation of Hex into HEX (4 of 5), Read 68 times
Conf: VEDIT Macro Language Support
From: Christian Ziemski
Date: Saturday, September 02, 2000 04:00 AM

>// Converting an ASCII 2-digit hex value into it's "real" hex value
>//
>// Cursor positioned on the first byte of the hex value
>
>Ins_Text("0x")
>Char(-2)
>#11=Num_Eval(SUPPRESS)
>Del_Char(4)
>Ins_Char(#11)

Or with the new upcoming VEDIT 5.20:

Reg_Set(99,"0x")
Reg_Copy_Block(99, Cur_Pos, Cur_Pos+2, APPEND+DELETE)
Ins_Char(Num_Eval_Reg(99, SUPPRESS))

Christian

 


Topic: Re: convert ASCII representation of Hex into HEX (5 of 5), Read 67 times
Conf: VEDIT Macro Language Support
From: Graham Walker
Date: Monday, September 11, 2000 11:11 AM

This worked a treat however I did seem to have to insert a space after the number I wanted to translate otherwise I got some spurious results. Any way thanks for the advice I would have never of thought of that method.

Cheers,
Graham

 


Topic: Re: convert ASCII representation of Hex into HEX (3 of 5), Read 66 times
Conf: VEDIT Macro Language Support
From: Ted Green
Date: Friday, September 01, 2000 02:06 PM

Here is a simple macro which converts an entire file from ASCII to "hex".

It is available at ftp.vedit.com/share/bin-hex.vdm.

The opposite macro to convert from hex to ASCII is available at ftp.vedit.com/share/hex-bin.vdm.

(I will try attaching these files to this message too.)


// BIN-HEX.VDM - Convert bytes to ASCII "Hex", similar to hex display mode.
//
// I.e., 0xff ==> "FF " (ASCII) (0x464620).
//
Config(F_OVER_MODE,0) //Turn off overwrite-only mode
if ( Config(F_F_TYPE) < 8) {
#10 = 0 //Flag - text file; don't convert CR+LF
} else {
#10 = Config(F_F_TYPE) //Flag - binary file; convert all chars
}

Begin_Of_File()
while (!At_EOF) {
if (!At_EOL || #10) {
#0 = (Cur_Char & 0xf0) >> 4
#1 = Cur_Char & 0xf
if ( #0 > 9 ) {
#0 = 'A' + (#0 - 10)
} else {
#0 += '0'
}
Ins_Char(#0,OVERWRITE)
if ( #1 > 9 ) {
#1 = 'A' + (#1 - 10)
} else {
#1 += '0'
}
Ins_Char(#1)
Ins_Char(' ')
} else {
Line(1)
}
}
//
// For binary file, add CR+LF at the current record length.
//
Config(F_F_TYPE,0,LOCAL) //Set the new file-type
Begin_of_File()
#11=0
if (#10>0) {
while (! At_EOF) {
Char(#10*3) //Advance past end of record
Ins_Newline(1) //Insert the Newline
#11++
//
// Display progress
//
if ( (#11 % 100)==0) {
Reg_Set(104,"Record # ")
Out_Reg(104,APPEND)
Num_Type(#11,LEFT+NOCR)
Out_Reg(CLEAR)
Message(@104,STATLINE)
}
}
}

(File attachment removed)