[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: BYTES to LONG



Paul van Delst wrote:
> 
> Kelly Dean wrote:
> >
> >  I am reading in a combination ASCII/BINARY file with USGS DLG
> > information as a binary file.
> >
> > I am able to convert the bytes into ASCII with STRING([72B, 101B, 108B,
> > 108B, 111B]).
> >
> > However, I cannot figure out how to convert the 4 bytes into LONG, whihc
> > is the UTM X and Y numbers. Any suggestions?
> >
> > Kelly
> 
> If I understand your question correctly,
> 
> if
> 
> x = [ 0B, 1B, 1B, 1B ]
> 
> then long_x = TOTAL( ISHFT( LONG(x), [24,16,8,0] ) )
> 
> ??
> 
> This gave me long_x = 65793.0 = 65536 + 256 + 1 which seems correct, no?
> 
> For some reason the TOTAL returned a floating point number? Weird. Never noticed that
> before.
> 

The total() function always converts to floating point before the sum,
to avoid overflow issues.  Consider:

a=total(bindgen(256))

if it did the total as bytes, that would overflow.  Of course, it could
have done them as regular ints, but how should it decide, a priori?  I
for one use total a lot in testing various conditions, and it always
bothered me that I had to test the floating result, but there's really
no other clean solution.

JD

-- 
 J.D. Smith                  |   WORK: (607) 255-6263
 Cornell Dept. of Astronomy  |         (607) 255-5842
 304 Space Sciences Bldg.    |    FAX: (607) 255-5875  
 Ithaca, NY 14853            |