Subject: Re: help: IBM mainframe binary fp specs

From: [email-masked] (Chris Flatters)
Date: Fri, 13 Aug 93 16:52:48 GMT

In article [email-masked], [email-masked] (Dan Braithwaite) writes:
>
>Hello,
>
>	I found this newsgroup just in time.
>
>	There is a strong possibility that I will acquire, very soon, 
>	a ton of data from an IBM mainframe in floating point binary
>	format.
>
>	I use a Sun workstation running unix and openwindows.
>
>	If a tool exists to convert between the two that would be
>	great.  If someone has the specs that would be just fine.
>
>	I am familiar, but not fluent, with the method of byte swapping
>	IBM PC binary data to make it readable on my system and I
>	hope this task is as straightforward

It isn't.  IBM mainframes use a radix-16 representation while Sun
workstations, IBM PCs and almost everything else use radix-2.  Even if
you have the specs for the IBM format, performing the conversion
without loss of precision is going to be a very challenging exercise in
bit-twiddling.

	Chris Flatters
	[email-masked]

---

From: [email-masked] (Ilana Stern)
Date: Fri, 13 Aug 1993 20:37:07 GMT

(I would have emailed it but from another response, it seems like
this is a not uncommon question!)

> 	great.  If someone has the specs that would be just fine.

Here is a subroutine.  (I didn't write it.)  The routines gbytes and
sbytes, which it uses, are available via anonymous FTP from
ncardata.ucar.edu in the directory /libraries/gbytes.

      SUBROUTINE UNP360(IN,IO,N)                                                
      PARAMETER (IWSZ=32)
C FOR EXECUTION ON WORD SIZE IWSZ (>=32)
C CONVERTS ARRAYS OF IBM 360/370 WORDS WHICH ARE IN A CONTINUOUS BIT            
C       STREAM INTO Sun WORDS.                                                 
C WILL ACCEPT MIXED ARRAYS OF REAL (REAL*4) AND INTEGER (INTEGER*4)             
C       AND RETURNS THE APPROPRIATE Sun REAL OR FULL WORD INTEGER              
C       VALUES.                                                                 
C       IN = ARRAY CONTAINING 360 WORDS AS A CONTINUOUS BIT STREAM. 
C       IO = ARRAY FOR Sun OUTPUT WORDS.                                       
C       N  = NUMBER OF VALUES TO CONVERT.                                       
      DIMENSION IN(1),IO(1)                                                     
      IOF=0                                                                     
      DO 20 I=1,N                                                               
      CALL GBYTES(IN,IS,IOF,1,0,1)                                              
      IOF=IOF+1                                                                 
      CALL GBYTES(IN,IEX,IOF,7,0,1)                                             
      IOF=IOF+7                                                                 
      CALL GBYTES(IN,IFR,IOF,24,0,1)                                            
      IF(IEX .EQ. 0 .OR. IEX .EQ. 127) GO TO 10                                 
      XV=FLOAT(IFR)*16.**(IEX-70)                                               
      IF(IS .NE. 0) XV=-XV                                                      
      CALL SBYTES(IO(I),XV,0,IWSZ,0,1)
      GOTO 20                                                                   
   10 CONTINUE                                                                  
      IF(IS .NE. 0) IFR=IFR-16777216                                            
      IO(I)=IFR                                                                 
   20 IOF=IOF+24                                                                
      RETURN                                                                    
      END                                       
-- 
/\
  \_][ <--NCAR Ilana Stern dod#009 r.b. cliff swallow [email-masked]    
      \______________________________________________________________________

---

From: [email-masked] (Paul Kunz)
Date: Fri, 13 Aug 1993 21:17:19 GMT

In article <[email-masked]> [email-masked]  
> >	hope this task is as straightforward
   First IBM mainframes are big-endian, so no byte swapping is needed.
>From the most significant bit to least you have...
- 1 bit for the sign
- 7 bits for the exponent offset by 64 and exponent is power of 16
- 24 bits mantissa single precision, 48 bits mantissa double precision

   So, x41100000 is 1.0, that is,  1/16 * pow(16, 65-64)

> without loss of precision is going to be a very challenging exercise in

   Since the IBM mainframe format is radix-16, there can be up to three  
leading 0 bits in the mantissa.   Thus, the 24 bit mantissa has less  
precision than radix-2 formats with 24 bit mantissa.   And that's not  
counting the leading 1 bit assumption which effectively loses another bit.
--
Paul F. Kunz	[email-masked] (NeXT mail ok)
Stanford Linear Accelerator Center, Stanford University
(home of the 370 emulators, circa 1976)
Voice: (415) 926-2884   (NeXT) Fax: (415) 926-3587