It's not yet at all easy to do this in COBOL; but it will be possible, even
in a certain sense easy, after someone implements the new standard, which
makes bit strings available.
To make clear what is involved here is a PL/I procedure:
ptrhexF: procedure(ptr)
returns(character(8))
reorder;
/* This function returns an eight-character string containing
a printable or displayable representation of its pointer argu-
ment's hexadecimal value. Moving from left to right in this
pointer argument, successive four-bit substrings of its value
are moved into the rightmost four bits of a previously zeroed
fullword, to obtain one of the values
|000000000000000000000000|0000|
|<------invariant-------------------->|0001|
|<------invariant-------------------->|0010|
|<------invariant-------------------->|0011|
|<------invariant-------------------->|0100|
| . . . . . . . . . . . . . . . . . . . . . . . . .| |
|<------invariant-------------------->|1110|
|<------invariant-------------------->|1111|
This value is then used as a subscript to extract a character
from the array HEXDICT, which is stowed in the corresponding
position in the output string ptrhexcs.
Pointers that have the special values null and sysnull need
not be and are not treated as special cases. They yield the
respective values [x]'ff000000' and [x]'00000000'.
version 3, modification level 0, 2004November, John Gilmore
/* parameter */
declare ptr pointer parameter nonassignable ;
/* named constants, static aggregate, builtins */
declare (F0 value(0b), F1 value(1b), F4 value(100b),
F8 value(1000b), F29 value(11101b))
binary fixed(31,0) ;
declare HEXDICT(0:15) static character initial
('0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f') ;
declare (addr, substr) builtin :
/* aliasing templates */
declare ptr_bitstring_alias
aligned bit(32) based(addr(ptr)) ;
declare i_bit-string_alias
aligned bit(32) based(addr(i)) ;
/* LIFO scratch storage */
declare (i, j, k) binary fixed(31,0),
ptrhexcs character(8) ;
i = F0 ;
do j = F1 to F8 ;
k = (j - F1) * F4 + F1 ;
/* generates the sequence: 1, 5, 9, . . . 29 */
substr(i_bit_string,F29,F4) = substr(ptr_bit_string,k,F4) ;
/* moves j-th pointer half-byte into four low-order bits of i */
substr(ptrhexcs, j, F1) = HEXDICT(i) ;
/* stows corresponding 'hex' character in output */
end ;
return(ptrhexcs) ;
end ptrhexF ;
For now, an HLASM subroutine or a version of this PL/I function that
specifies OPTIONS(COBOL) in its procedure statement is about the best you
can do.
John Gilmore
Ashland, MA 01721-1817
USA
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [EMAIL PROTECTED] with the message: GET IBM-MAIN INFO
Search the archives at http://bama.ua.edu/archives/ibm-main.html