From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=BAYES_00,INVALID_MSGID, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,bb7e1240dd9c863e,start X-Google-Attributes: gid103376,public From: pontius@twonky.btv.ibm.com (Dale Pontius) Subject: Re: GNAT Ada on DOS and UNIX- Writing a binary file of Integers problems Date: 1996/02/20 Message-ID: <4gchf6$397@twonky.btv.ibm.com>#1/1 X-Deja-AN: 140257131 distribution: world references: <4gcf25$jvn@susscsc1.rdg.ac.uk> organization: IBM Technology Products reply-to: pontius@vnet.ibm.com newsgroups: comp.lang.ada Date: 1996-02-20T00:00:00+00:00 List-Id: In article <4gcf25$jvn@susscsc1.rdg.ac.uk>, William Paul Berriss writes: > > I have written an Ada95 program which reads in Sun raster files. The header > is read in and give me the numbers 512 512 24 1 etc These are the image's > size and no. of bits etc. These I read in from the standard image of peppers. > The numbers are also printed to the screen so I can see what they are. > I then ftp the peppers.ras image to a DOS PC. I also ftp the Ada program > to DOS and compile it on GNAT for DOS. It compiles and runs fine. > > What it does is this: > When reading in the peppers.ras file it gets the nymbers form the header BUT > instead of 512 it shows (on the screen) 131072, and instead of 24 it shows > 402653184 (which is 16777216 time too big!). > And instead of the number 786432 It gives me a number that is too small, > it gives 3072 (i.e. timesd by 256). > All these 'wrong' numbers can be made from > other numbers, e.g. 131072 is 256 times 512. It should have been 512! > > The image is fine, I can view it on PaintBrush for windows say. > Also, if I strip this header of 'huge' numbers and replace it with the > numbers 512 ,512, 24, 1 etc then when I read it in again I do get the correct > numbers, 512, 512 ,24, 1 etc. But then, of course? , PaintBrush cannot read in > the image. Obviously the numbers look 'funny' to IT ! > > I think I once had a unix binary file and when I viewed it on a PC the > bytes for the numbers' mantissa and exponent were interchanged- hence I > had weird numbers then! > > What is happening with GNAT? Is GNAT for DOS producing a binary file > suitable for UNIX go32 operating system? and so any software for DOS (16 bit) > cannot read it? > > Do you know how I can try to find out what is happening? or fix this problem. > I am sure I am not the only one to have noticed this!? Am I ? > This looks like 'classic byte sex' to me, or little-endian vs big-endian. Whenever you may be reading files from the wrong endian machine you have to be ready to flip the bytes. Unfortunately, this can't be done in any simple fashion, you have to flip the bytes in a very data-dependent way. Write yourself some sample binary data on the Sun, then carry it over to the PC and read it. You can soon see the pattern emerging. I once had to do this between PC and mainframe, plus whenever I hit text translate from EBCDIC to ASCII. Dale Pontius (NOT speaking for IBM)