comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: Read Hex numbers
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: Read Hex numbers [message #5255] Fri, 24 November 1995 00:00
boswell is currently offline  boswell
Messages: 7
Registered: October 1994
Junior Member
Apologies to the group for the wasted bandwidth of my last post.

Michael is reading in his binary data just fine, he simply wants to print out
the result in hex. My last answer had the right idea, but my example was
backwards.

What you want to do is use the Z format specifier on output. This works fine
in IDL. For example, if you want to output nibbles of your 2 byte array, you
could use a statement such as

IDL> print, bytearray, format='(2Z2)'

Jonathan Boswell
FDA/CDRH
Re: Read Hex numbers [message #5256 is a reply to message #5255] Fri, 24 November 1995 00:00 Go to previous message
Frank J. �ynes is currently offline  Frank J. �ynes
Messages: 17
Registered: February 1995
Junior Member
SLAMECZKA@EZINFO.VMSMAIL.ETHZ.CH (SLAMECZKA,MICHAEL) wrote:
> 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
>
> Has anybody some ideas, how I can handle this problem?
>
> thanks in advance
>
> michael

Maybe I'm stupid, but I don't understand your question.
Or are you mixing some terms here?

Is your file really binary, or is it an ascii representation of
binary numbers?
What do you mean by "read it in HEX" ?


Please clarify, and I'll try to help.
--
/* Frank J. �ynes | frank@spacetec.no /*
/* Spacetec a.s | Phone: +47 77684500 Fax: +47 77655859 /*
/* Prestvannv. 38, | /*
/* N-9005 Troms�, Norway | (...with the bravery of being out of range!) /*
Re: Read Hex numbers [message #5262 is a reply to message #5255] Fri, 24 November 1995 00:00 Go to previous message
rivers is currently offline  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)
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Problems transferring an XDR file.
Next Topic: Representing graphs in IDL

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 19:21:14 PDT 2025

Total time taken to generate the page: 0.00596 seconds