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

Home » Public Forums » archive » Re: Convert a byte array to a structure?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Convert a byte array to a structure? [message #28976 is a reply to message #28877] Sat, 26 January 2002 00:06 Go to previous message
sven is currently offline  sven
Messages: 1
Registered: January 2002
Junior Member
> Problem is this:
> Lets say we have an arbitrary array of bytes, of length n. We also have
> a field, of n bytes length, that needs to be filled with that data as
> the concatenation of those values. As an example:
>
> ['ff'x,'01'x] -> 'ff01'x -> 65281
>
> BYTE[2] -> intermediate step (?) -> FIX[1]
>
> Would it be possible to do this with other size fields (like converting
> 4 bytes to a floating point number etc.)? Simply 'gluing' the elements
> of they byte array together, like 255*byte[0]+ byte[1] won't work with
> floating point numbers (?). I suspect the solution may involve pointers
> somehow, but I'm not sure how it might be done.


I am quite possibly missing something here, but why don't you use the
standard typecasting functions like fix() and float() ?


IDL> b = ['66'xb,'66'xb,'8a'xb,'41'xb]
IDL> help,b
B BYTE = Array[4]
IDL> print,b
102 102 138 65
IDL> print,float(b,0)
17.3000
IDL> print,fix(b[0:1],0)
26214


Isn't that what they're there for?



-- Sven Geier
/'''
c-OO This .signature is under the GNU public license. You may copy, use
\ > and distribute verbatim copys of it, as long as this notice and the
\_v name of the author are left intact.
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: nested subroutines and scope
Next Topic: max, mean, min of array

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

Current Time: Thu Oct 09 20:00:27 PDT 2025

Total time taken to generate the page: 0.56023 seconds