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

Home » Public Forums » archive » 32-bit Unsigned Integers, Was: Unsigned Integers - How?
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: 32-bit Unsigned Integers, Was: Unsigned Integers - How? [message #8167 is a reply to message #8110] Thu, 13 February 1997 00:00 Go to previous messageGo to previous message
plugge is currently offline  plugge
Messages: 17
Registered: May 1995
Junior Member
In article <330039AF.23DB@star.sr.bham.ac.uk>, James Tappin
<sjt@star.sr.bham.ac.uk> writes:
|>David Fanning wrote:
|>[SNIP]
|>
|>>
|>> Now, here is where I start to get unsure of myself. I know
|>> how to turn *one* unsigned 32-bit integer into its real value.
|>> You use the BYTE function to individually read the four
|>> bytes of information in the 32-bit integer and you reconstruct
|>> those bytes into a DOUBLE-PRECISION value. The code looks
|>> like this:
|>>
|>> number = data(0)
|>> factor = 256.0D
|>> realNumber = BYTE(number, 0)*factor^3 + BYTE(number,1)*factor^2 +$
|>> BYTE(number,2)*factor^1 + BYTE(number,3)*factor^0
|>>
|>> This is for a big endian machine, like most UNIX machines. If
|>> you are on a little endian machine (like a PC), you will have to
|>> reverse the order in which the real number is constructed. Your
|>> code will look like this:
|>>
|>> number = data(0)
|>> factor = 256.0D
|>> realNumber = BYTE(number, 0)*factor^0 + BYTE(number,1)*factor^1 +$
|>> BYTE(number,2)*factor^2 + BYTE(number,3)*factor^3
|>>
|>> What I don't know how to do (perhaps Bill Thompson or Mitchell Grunes
|>> can help us here), is how to do this for the whole array at once in
|>> an "array" type way. I certainly know how to write a loop! :-)
|>>
|>> realNumbers = DBLARR(N_ELEMENTS(data))
|>> factor = 256.0D
|>> FOR j=0, N_ELMENTS(data)-1 DO BEGIN
|>> realNumbers(j) = BYTE(data(j), 0)*factor^0 + BYTE(data(j),1)*factor^1
|>+$
|>> BYTE(data(j),2)*factor^2 + BYTE(data(j),3)*factor^3
|>> ENDFOR
|>>
|>
|>Here's my version in vector form
|>

another vector version:

x=2000000000L+ 1000000000L ;a large integer
help,x
y=replicate(x, 4,4) ;generate the array
y(0,0)=1 ;some values should be positive
y(1,1)=10
y(2,2)=100
y(3,3)=1000
print,y
w=where(y lt 0) ;check for negative values
s=size(y)
dbl=make_array(/double,size=s) ;make the new array
help,dbl
dbl(0,0)=y
dbl(w)=dbl(w)+4294967296d0 ;that's it!! ;-)))
print,dbl
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: DICOM images: anyone written code to read them?
Next Topic: Re: Exceed with IDL

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

Current Time: Sun Oct 12 04:38:59 PDT 2025

Total time taken to generate the page: 0.64200 seconds