View previous topic :: View next topic
|
Author |
Message |
aprak00 Warnings : 2 New User
Joined: 09 Aug 2006 Posts: 24
|
|
|
|
Could anyone please let me know how to convert COMP-1 and COMP-2 to readable format using REXX? I am able to convert Binary and Packed decimals to readable format. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
when asking REXX questions refrain from using COBOLESE,
if You use COBOLESE You will limit the number of people able to reply,
not all the people proficient in REXX use that other language..
but... if instead of asking You had done a bit of homework You would have found this
www.connelley.org/Coding_Examples/c2f.html |
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1306 Location: Vilnius, Lithuania
|
|
|
|
Or this, if you need extended floating points (no clue as to what they are in the COBOL world...):
Code: |
/* This REXX exec computes a S/370 floating-point's value ...
e.g. X'C1280000' represents -2.5
(Michel Castelein, 5 November 1997)*/
say 'Enter the S/370 floating-point (4, 8, or 16 bytes):'
numeric digits 34
pull float
float = X2C(float) /* convert float to a hexadecimal string*/
float_size = LENGTH(float) /* size in Bytes*/
Byte_0 = SUBSTR(float, 1, 1)
select
when BITAND(Byte_0, '80'x) == '00'x then sign = '+'
when BITAND(Byte_0, '80'x) == '80'x then sign = '-'
end
exponent = C2D(BITAND(Byte_0, '7F'x)) - 64
fraction = 0
power = -1
do i = 2 to float_size
if i = 9 then iterate /* skip bits 64-71*/
Next_Byte = C2D(SUBSTR(float, i, 1))
left_Digit = Next_Byte % 16
fraction = fraction + left_Digit * 16**power
right_Digit = Next_Byte // 16
power = power - 1
fraction = fraction + right_Digit * 16**power
power = power - 1
end
interpret 'value =' sign ( fraction * 16 ** exponent )
say "The floating-point's value is" value
say
say 'Press Enter to continue'
pull
return
/*
TEST_WORK.FS=1.00000E+01;
TEST_WORK.FL=1.000000000000000E+01;
TEST_WORK.FE=1.00000000000000000000000000000000E+01;
'41A00000'B
'41A0000000000000'B
'41A00000000000003300000000000000'B
TEST_WORK.FS=3.16227E+00;
3.16227722167968750000
TEST_WORK.FL=3.162277660168379E+00;
3.162277660168379300742458326567430049181
TEST_WORK.FE=3.16227766016837933199889354443270E+00;
3.162277660168379331998893544432716995013
'413298B0'B
'413298B075B4B6A5'B
'413298B075B4B6A533240945790619B3'B
*/ |
|
|
Back to top |
|
|
aprak00 Warnings : 2 New User
Joined: 09 Aug 2006 Posts: 24
|
|
|
|
Thank you Prino... |
|
Back to top |
|
|
|