Contents | Index | < Browse | Browse >
Tips Section:
------------
1)WRITING BINARY AND HEX STRINGS -Ernest Unrau
2)MEMORY ADDRESSES AND HEX CODE -Guido Mersmann

***

1)WRITING BINARY AND HEX STRINGS:
------------------------------

-By Ernest Unrau

This method is not documented in the Arexx manuals. Thanks instead to other programmers who demonstrated the technique in their scripts.

It is sometimes useful to include a binary or formatted string into your ARexx program code by converting it to text string in Hexadecimal code. This allows one to include the binary information, yet continue to edit the script in a text-only editor.

ARexx allows one to convert the string back to its character representation simply by quoting the string and adding the binary or hex designator.

Examples:

The character 'a' in binary code is 01100001. You can produce this conversion at the shell command line interface with the command:
rx "say c2b('a')"
outputs,
01100001
To convert back in the script, use this command in the shell:
rx "say '01100001'b"
outputs
a

The character 'a' in hexadecimal code is 61. You can produce this conversion at the shell command line interface with the command:
rx "say c2x('a')"
outputs,
61
To convert back in the script, use this command in the shell:
rx "say '61'x"
outputs
a

Similarly you can convert the string from its character representation to decimal:
rx "say c2d('a')"
outputs,
97
but there doesn't seem to be a similar way to convert the string back:
rx "say '97'd"
does not work. Instead it outputs,
97D
For this it appears you must use the function,
rx "say d2c(97)"



2)MEMORY ADDRESSES AND HEX CODE
-----------------------------

Explanation of the memory values output by the SYS:Tools/Showconfig command

Example:

RAM: Node type $A, Attributes $505 (FAST), at $7000000-$7FFFFFF (16.0 meg)
Node type $A, Attributes $703 (CHIP), at $4000-$1FFFFF (~2.0 meg)

These addresses converted to decimal,

rx "say x2d('7000000') '-' x2d('7FFFFFF')

are,
117440512 - 134217727

Why?

***
-by Guido Mersmann <geit@gmx.de>

Date: Thu, 23 Sep 2004 10:56:06 +0100
From: Guido Mersmann <geit@gmx.de>
Subject: Re: Address numbers

First never convert them to decimal, because they become ugly and worse to
handle.

To make it simple. One megabyte is 0x100000. [Ed. note: in rexx that would be '100000'x or x2d('100000')]

Your memory ranges from 7000000 to 8000000.
^ ^
So the imporant megabyte counter makes one cycle. It's like counting from 10 to 20 (in decimal). The last (right) digit makes a full count from 0 to 0. So you count by the value of 10. With hex values this is the same when counting from 0 to 0, (but) they count 16 times a cycle.

[Ed. note:
Hexadecimal counts this way:
00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 etc.
In decimal this is,
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 etc.]

So you need 16 * 100000 to get from 7000000 to 8000000. Thats 16MB.

Re.
> 117,440,512
> 134,217,727

Address != Amount

It's starting at 117... and ending at 134. To get its size you simply need to subtract them and you'll get 16,777,216. If you divide by 1024 you'll get 16364 KB and if you divide again you'll get 16MB.

Using hex is more simple: 0x8000000 - 0x7000000 = 0x1000000 (see above about the 8000000). Now since 0x100000 is 1 MB: 0x1000000 / 0x100000 = 0x10. 0x10 is 16 in decimal.

BTW: 7fffffff is the last byte, so you need to add 1 to get 8000000. It's like measuring a distance. You take the distance till behind the last inch and not 'til the beginning of the last inch.

The software you used [showconfig] reports the last byte of memory and not the end of memory.

also weg und so na denn und schuesss !!!

-Guido