data = 123
and convert it so that the variable's value is actually 123
(that's the number 123, NOT a character string consisting
od ASCII 1 followed by ASCII 2 followed by ASCII 3... which
I think is 31, 32, 33)
I need to pass these variables as integers to a device driver.
In fact, REXX must have this built in, otherwise how could it
do addition with variables saved as strings?
Any help appreciated,
Thanks
Dan
Dan,
With no experience with your specific applications...
Assume mode on.
(1) the functions are returning a "string" of decimal digits, e.g., "12"
or "1234"
(2) you want these to be hexified, e.g., "C" or "4D2"
A mode off.
Rexx _automatically_ handles the string-to-decimal stuff (and the
reverse) all the time.
So your "problem" really is decimal-to-hex, or
hex_value = D2x(decimal_value)
These kind of things should do it:
dtemp1 = function1(...)
dtemp2 = function2(...)
dtemp3 = temp1 || temp2
xtemp = D2x(dtemp3)
rc = IOCTLfunc(xtemp3)
This "long form" lets you "see" exactly what is happening when run with
Trace ?R and is also easier to write and read correctly!
Or, a little faster in execution and using less memory:
rc = IOCTLfunc(D2x(function1(...) || function2(...)))
Hope this is a little clearer than the previous.
--
Jeff Hennick
JHen...@Delphi.Com (temp:) JHen...@MCI.NewsCorp.Com
: data = 123
: and convert it so that the variable's value is actually 123
: (that's the number 123, NOT a character string consisting
: od ASCII 1 followed by ASCII 2 followed by ASCII 3... which
: I think is 31, 32, 33)
Rexx has six functions to convert values between decimal, hexadecimal
and character. They are: c2d(), d2c(), c2x(), x2c(), x2d(), d2x().
For your question, use decimal to character d2c().
Try the following:
data=123
data_char=d2c(data)
and you will have your integer value on the variable data_char.
You can also do directly data_char=d2c(123).
Rexx does not store numbers as integers and it does no mathematics
using integers. It does accounts like we learn in school, digit by
digit. The advantage is you have no limit to the precision.
By default, REXX works with nine digits for the numbers, but you can
override it and do whatever precision you want.
Try this:
numeric digits 999999 /* tells REXX to use 999999 digits for numbers */
aaa = 7652376512736517657865977566876876765 / 3325876876892228726666
say aaa
if you have enogh memory, you will get lots of screens filled with numbers!
Hope this helps.
Luis Paulo
Rexx's arithmetic is defined and implemented as operations on strings, believe
it or not :-) . This gives a lot of portability at the expense of speed.
I think what you mean is 123 as it would be physically in C ie in binary. The
function d2x( 123 ) gives this (7B).
Yours, Patrick
__________________________________________________________________
Patrick Herring, Primrose Hill, London, UK
I tend to eat my UUCP feed once a day so replies can take two days
>I need to pass these variables as integers to a device driver.
Dan,
To convert a numeric string to a two-byte integer you should use:
nNumber = '1234' /* = '31323334'x in ASCII */
cInteger2 = d2c(nNumber,2) /* = '04D2'x */
If you are passing this integer to an assembly language routine on a
big-endian machine (eg IBM S/390) then this is fine. If the machine
is little-endian (eg Intel 80x86) you will have to reverse the bytes
first:
cInteger2 = reverse(d2c(nNumber,2)) /* = 'D204'x */
Explicitly specifying the length ensures that a short (80x86) int is
always generated, otherwise REXX will use the mininum number of bytes
to store the result. A long (80x86) int would be generated by:
cInteger4 = reverse(d2c(nNumber,4)) /* = D204'0000'x */
I don't want to labour the point, but using d2x is inappropriate since
it converts a decimal string to a hex STRING:
sHex = d2x(nNumber,4) /* = '30344432'x in ASCII */
...which is not an integer, but a string.
BTW, I have found it useful to use (a variation of) Hungarian notation
to reduce confusion about what is actually stored in REXX variables.
Examples of prefixes I use are:
sString = 'hello'
nNumericString = '1234'
xHexString = '4D2'
cBinaryString = '04D2'x
bBoolean = 1
...but there are exceptions which dont fit in from time to time..
== == ===== ==== Andrew J. Armstrong
== == ====== ====== Managing Director
====== == == == == HPO Computer Services Pty Ltd
====== ====== == == Sydney, Australia
== == ===== ====== Voice: +61 2 041 111 0245
== == == ==== Internet: ajar...@ozemail.com.au
This is the Hex value. You can get binary value with d2c(). If you look at
the output you see "{" .
>
>Yours, Patrick
>__________________________________________________________________
>
>Patrick Herring, Primrose Hill, London, UK
>I tend to eat my UUCP feed once a day so replies can take two days
>
--
Wim Kok 2405 ZJ Alphen ad Rijn The Netherlands
Phone: 0172-424536 email: w...@wims.ow.nl
/* value is a buit-in function provided by REXX */
Hmm, yes, elementary mistake by me, oh dear. Still, as Dan said, it's a
confusing part of Rexx in that the input to d2c() is a char string and you get
back a binary number. One thing the thread did show up is that there is no one
thing that is 'really' a number in Rexx. Coming from COBOL I'm not surprised.
Yours, Patrick
_____________________________________________________________________________
I missed the previous postings in this thread, but the above is
redundant. Equivalent code is:
number = '1234'
val = number /* same effect as value(number), in this case */
number = 1234 /* identical to above... */
val = number
REXX numerics are strings. No special conversion of this kind is
required, unlike many other languages with distinct variable types.
------------------------------------------------------------------------
Peter HANSEN Engenuity Corporation
pe...@engcorp.com Guelph, Ontario, Canada
http://www.sentex.net/~engcorp/peter/
------------------------------------------------------------------------
No, actually you get back a byte (a.k.a. a character), which is what you
should expect from the name of the function "decimal-2-character". You
input a string containing digits which are interpreted as base ten, and
you get out a byte whose value matches that decimal number. The byte can
be represented as a character (which is is when REXX prints it), or as a
decimal number, a hex number, or a binary number such as 00100101. If
you want to get back the actual binary number, you need to use
x2b(d2x(decimal_number_in_string))
>One thing the thread did show up is that there is no one
>thing that is 'really' a number in Rexx.
There are numbers in REXX. You can't do "say 4*5" without numbers. I
think you meant to say there is no true numeric data storage type, and
that's basically true, if largely unimportant other than from the point
of view of speed.