Re: Read Hex numbers [message #5262 is a reply to message #5255] |
Fri, 24 November 1995 00:00  |
rivers
Messages: 228 Registered: March 1991
|
Senior Member |
|
|
In article <494frp$4p7@elna.ethz.ch>, SLAMECZKA@EZINFO.VMSMAIL.ETHZ.CH (SLAMECZKA,MICHAEL) writes:
> Hello everybody!
>
> I have the following problem; i have a binary file, which I wanna read. I know
> that pw-wave can read this file in binary, ascii, integer, float and complex,
> but I need to read it in HEX, that means
>
> a sequence looks like this: 0001 1001 0100 0011
> and PW-Wave should display: 1 9 4 3
>
> with a bytearray the output looks like this: 25 67
It looks like you want to read the data into "nibbles" of 4 bits each, rather
than bytes of 8 bits each. This is really not "read in HEX". It think the
following will do what you want.
IDL> bytes = bytarr(1000)
IDL> nibbles = bytarr(2,1000)
IDL> READU, 1, bytes
IDL> nibbles(0,*) = bytes and '0f'x
IDL> nibbles(1,*) = bytes/16 and '0f'x
IDL> nibbles = reform(nibbles, 2000)
Note that the lines 4 and 5 are architecure dependent: the assignment depends
upon whether you have a big-endian or little-endian machine.
____________________________________________________________
Mark Rivers (312) 702-2279 (office)
CARS (312) 702-9951 (secretary)
Univ. of Chicago (312) 702-5454 (FAX)
5640 S. Ellis Ave. (708) 922-0499 (home)
Chicago, IL 60637 rivers@cars3.uchicago.edu (Internet)
|
|
|