Hexadecimal calculations with REXX

REXX is a precursor of modern script languages such as perl, python and others. However, it’s somewhat harder to do hexadecimal calculations with REXX, so I made a small test program for clearing up all this. See code below:

#!/usr/bin/regina
/* differences between character and number formats */
say Test 1
i = '3a'x            /* char */
say i                /* displays : */
say c2x(i)           /* displays 3A */
/* say x2d(i) */     /* displays Invalid hexadecimal or binary string */
say datatype(i)
say

say Test 2
i = '4152'x          /* char */
say i                /* displays AR */
say c2x(i)           /* displays 4152 */
/* say x2d(i) */     /* displays Invalid hexadecimal or binary string */
say datatype(i)
say

say Test 3
i = '44d855aa'x      /* char */
say i                /* displays D(?)U(?) where (?) is a ? in reverse video */
say c2x(i)           /* displays 44D855AA */
/* say x2d(i) */     /* displays Invalid hexadecimal or binary string */
say datatype(i)
say

say Test 4
i = '3ad855aa'       /* char (string) */
say i                /* displays 3ad855aa */
say c2x(i)           /* displays 3361643835356161 */
say x2d(i)           /* displays 987256234 */
say datatype(i)
say

say Test 5
i = 65535            /* num */
say i                /* displays 65535 */
say c2x(i)           /* displays 3635353335 */
say x2d(i)           /* displays 415029 */
say datatype(i)
say

say Test 6
i = c2x('3ad8'x)     /* char */
say i                /* displays 3AD8 */
say c2x(i)           /* displays 33414438 */
say x2d(i)           /* displays 15064 */
say datatype(i)
say

say Test 7
i = c2d('3ad8'x)     /* num */
say i                /* displays 15064 */
say c2x(i)           /* displays 3135303634 */
say x2d(i)           /* displays 86116 */
say datatype(i)
say

say Test 8
i = c2x('3ad8')      /* num */
say i                /* displays 33616438 */
say c2x(i)           /* displays 3333363136343338 */
say x2d(i)           /* displays 862020664 */
say datatype(i)
say

say Test 9
i = c2d('3ad8')      /* num */
say i                /* displays 862020664 */
say c2x(i)           /* displays 383632303230363634 */
say x2d(i)           /* displays 36004038244 */
say datatype(i)
say

say Test 10
i = c2x('3ad855aa'x) /* char */
say i                /* displays 3AD855AA */
say c2x(i)           /* displays 3341443835354141 */
say x2d(i)           /* displays 987256234 */
say datatype(i)
say

say Test 11
i = c2d('3ad855aa'x) /* num */
say i                /* displays 987256234 */
say c2x(i)           /* displays 393837323536323334 */
say x2d(i)           /* displays 40922079796 */
say datatype(i)
say
exit 0
Advertisements
This entry was posted in Software and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s