comp.lang.ada
 help / color / mirror / Atom feed
* Re: GNAT Ada on DOS and UNIX-  Writing a binary file of Integers problems
       [not found] <4gcf25$jvn@susscsc1.rdg.ac.uk>
@ 1996-02-20  0:00 ` Dale Pontius
  0 siblings, 0 replies; only message in thread
From: Dale Pontius @ 1996-02-20  0:00 UTC (permalink / raw)



In article <4gcf25$jvn@susscsc1.rdg.ac.uk>, William Paul Berriss <strberis> 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)




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1996-02-20  0:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <4gcf25$jvn@susscsc1.rdg.ac.uk>
1996-02-20  0:00 ` GNAT Ada on DOS and UNIX- Writing a binary file of Integers problems Dale Pontius

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox