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

Re: BYTES to LONG



Kelly Dean (krdean@lamar.colostate.edu) writes:

>  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?

This is the purpose of the Offset parameter in the LONG
function. If you use an offset into a byte array, it will
then extract the next 4 bytes as a long integer. 

Here is a little example program to show you how it works.
The important part is where the byteValues are converted
to LONGs:

PRO TEST

data = [1L, 4L, 8L, 12L]
OpenW, lun, 'test.dat', /Get_Lun
WriteU, lun, data
Free_Lun, lun

byteValues = BytArr(16)
OpenR, lun, 'test.dat', /Get_Lun
ReadU, lun, byteValues
Free_Lun, lun

longValues = LonArr(4)
For j=0,3 DO longValues[j] = Long(byteValues, j*4)
Print, longValues

END

Cheers,

David

-- 
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155