Topic: Writing in Hex (1 of 6), Read 26 times
Conf: Hex, Binary, EBCDIC
From: mendel deren
Date: Tuesday, October 28, 2008 02:42 PM

B"H
Please, can you tell me how to do the following:

I want to write a Hex file based on numbers stored in Numeric registers.

e.g. If Reg#25 contains the number 255 and Reg#26 contains the number 0,I want to create a Hex file that will read "FF OO." without any other bytes.

i.e in bitwise mode I will only see two bytes.


Also, can you tell me how to do the above if the numbers in the numeric registers are greater than 255 and I don't want to write more bytes than necessary for a number for example for numbers between 0 255 I would write one byte and between 256 and 65535 I would write two bytes etc.

Thank You for your help,
Mendel

 


Topic: Re: Writing in Hex (2 of 6), Read 30 times
Conf: Hex, Binary, EBCDIC
From: Christian Ziemski
Date: Tuesday, October 28, 2008 04:43 PM

On 28.10.2008 19:58 in vtech-hex-ebcdic Mendel Deren wrote:
>
> I want to write a Hex file based on numbers stored in Numeric
> registers.
>
> e.g. If Reg#25 contains the number 255 and Reg#26 contains the number
> 0,I want to create a Hex file that will read "FF OO." without any
> other bytes.
>
> i.e in bitwise mode I will only see two bytes.
>
>
> Also, can you tell me how to do the above if the numbers in the
> numeric registers are greater than 255 and I don't want to write more
> bytes than necessary for a number for example for numbers between 0
> 255 I would write one byte and between 256 and 65535 I would write
> two bytes etc.


For values lower than 256 it's easy. You can use Ins_Char().
For higher values it depends.

The following macro may be used as possible starting point.


//
// Write a binary file out of a block of numeric registers
//
// (Quick'n'dirty)
//

#104=10 // the first register
#105=20 // the last register

for (#103=#104 ; #103<=#105 ; #103++) { // loop through registers

#106=#@103 // get content of current numeric register

if (#106 < 256) { // if it's only one byte

Ins_Char(#106) // write it directly

} else { // otherwise divide it into several bytes...
// This algorithm may not the best one,
// but it works...
Out_Reg(103)
Num_Type(#106, HEX+NOMSG+NOCR) // write value as hex to t-reg 103
Out_Reg(CLEAR)
#107=Reg_Size(103) // get the # of hex digits of it

for (#108=0 ; #108<#107 ; #108+=2) { // loop through digits pairs
Reg_Set(104, "0x") // prepare a "hex" reg
Out_Reg(104, APPEND) // and append
Reg_Type_Block(103, #108, #108+2) // two hex digits (one byte)
Out_Reg(CLEAR) // to it
#109=Num_Eval_Reg(104) // evaluate dec value of byte
Ins_Char(#109) // insert it into the file
}
}
}



Christian

 


Topic: Re: Writing in Hex (3 of 6), Read 30 times
Conf: Hex, Binary, EBCDIC
From: mendel deren
Date: Wednesday, October 29, 2008 03:50 PM

B"H
Christian,
Thank You so much. It is indeed a good starting point.

Mendel

 


Topic: Re: Writing in Hex (4 of 6), Read 28 times
Conf: Hex, Binary, EBCDIC
From: Pauli Lindgren
Date: Friday, October 31, 2008 04:46 AM

On 10/28/2008 4:43:17 PM, Christian Ziemski wrote:
>
>The following macro may be used as
>possible starting point.

- To write a 16-bit number in numreg #10 using little endian (Intel) byte order:

Ins_Char(#10 & 0xff)
Ins_Char(#10 >> 8)

- To write a 32-bit number:

for (#1=0; #1<4; #1++) {
Ins_Char(#10 & 0xff)
#10 = #10 >> 8
}


By the way, Christian, how did you manage to retain the format and indents in the code? WebBoard meshes the format and (pre) tag does not work correctly.

--
Pauli

 


Topic: Re: Writing in Hex (5 of 6), Read 27 times
Conf: Hex, Binary, EBCDIC
From: Christian Ziemski
Date: Saturday, November 01, 2008 09:37 AM

On 10/31/2008 4:46:50 AM, Pauli Lindgren wrote:
>
>- To write a 16-bit number in numreg #10
>using little endian (Intel) byte order:
>
>Ins_Char(#10 & 0xff)
>Ins_Char(#10 >> 8)
>
>- To write a 32-bit number:
>
>for (#1=0; #1<4; #1++) {
> Ins_Char(#10 & 0xff)
> #10 = #10 >> 8
>}

Thank you Pauli for that bit mathematics!

Mendel didn't restrict it to max 16/32 bit so I tried to find an easy way for bigger numbers.

If there is an algorithm (using VEDITs mathematics) for byte-splitting even big numbers I would be interested.
(I don't need it - I'm just curious.)

>By the way, Christian, how did you
>manage to retain the format and indents
>in the code? WebBoard meshes the format
>and (pre) tag does not work correctly.

I'm still doing it more or less manually, using my old macro posted and described in "VEDIT macro library":
"Little helper to pre-format WebBoard messages 6/5/2004 (5)"
( http://webboard.vedit.com/read?17959,29 )

Christian

 


Topic: Re: Writing in Hex (6 of 6), Read 30 times
Conf: Hex, Binary, EBCDIC
From: Pauli Lindgren
Date: Monday, November 03, 2008 03:45 AM

On 11/1/2008 9:37:15 AM, Christian Ziemski wrote:
>On 10/31/2008 4:46:50 AM, Pauli Lindgren
>>
>> - To write a 32-bit number:
>>
>> for (#1=0; #1<4; #1++) {
>> Ins_Char(#10 & 0xff)
>> #10 = #10 >> 8
>> }
>
> Mendel didn't restrict it to max 16/32
> bit so I tried to find an easy way for
> bigger numbers.
>
> If there is an algorithm (using VEDITs
> mathematics) for byte-splitting even big
> numbers I would be interested.
> (I don't need it - I'm just curious.)

To write a 64 bit value (if you have Vedit Pro 64), just replace 4 with 8 in the for loop above. That is:
for (#1=0; #1<8; #1++) {
Ins_Char(#10 & 0xff)
#10 = #10 >> 8
}


> I'm still doing it more or less
> manually, using my old macro posted and
> described in "VEDIT macro library":
> "Little helper to pre-format WebBoard
> messages 6/5/2004 (5)"
> (
> http://webboard.vedit.com/read?17959,29
> )

Thanks, I don't remember seeing that message before.
I have done manual editing sometime, but even after removing the additional (br) tags so that there are no additional empty lines, the text font was still very small (depending on the browser used).

But I recall it was said that those who read WebBoard using e-mail only receive the first version of the message and not any modifications. Or are the e-mail messages only sent once a day or something like that?

--
Pauli