Re: understanding 'fix' command! [message #59823] |
Fri, 18 April 2008 12:16 |
vino
Messages: 36 Registered: March 2008
|
Member |
|
|
On 18 Apr, 17:32, FĂ–LDY Lajos <fo...@rmki.kfki.hu> wrote:
> On Fri, 18 Apr 2008, vino wrote:
>> Hi!
>> I was trying out the 'FIX' command and i couldnt understand all the
>> arguments present. Can someone help me please? below is whats i did!
>> IDL> c=[1.2,-3.4,5.]
>> IDL> print,fix(c)
>> 1 -3 5
>
> You have converted a float array to int.
>
> FIX converts to IDL int, which is 16 bits wide, is signed and its range is
> -32768 <= int <= 32767. I assume you know how numbers are represented in
> computers. (The following is valid on little-endian machines only.)
>
> Your float array occupies 12 bytes in memory, namely:
>
> 154 153 153 63 154 153 89 192 0 0 160 64 (in decimal)
>
>> IDL> print,fix(c,0)
>> -26214
>
> reads memory as int from offset 0: the two bytes 154, 153 give -26214
> (154+256*153 = 39322 = 65536-26214 = -26214)
>
>> IDL> print,fix(c,1)
>> -26215
>
> reads memory as int from offset 1: the two bytes 153, 153 give -26215
> (153+256*153 = 39321 = 65536-26215 = -26215)
>
>> IDL> print,fix(c,2)
>> 16281
>
> reads memory as int from offset 2: the two bytes 153, 63 give 16281
> (153+256*63 = 16281)
>
>> IDL> print,fix(c,0,1)
>> -26214
>
> same as first, reads 1 int (from offset 0)
>
>> IDL> print,fix(c,0,2)
>> -26214 16281
>
> same as first and third, reads 2 ints (from offset 0 and 2)
>
> regards,
> lajos
Hi Lajos,
Thank you very much for explaining me. I didnt know how floating point
numbers are represented in binary.
I understand it very well now. thank you very much,#
regards,
vino
|
|
|
Re: understanding 'fix' command! [message #59828 is a reply to message #59823] |
Fri, 18 April 2008 09:32  |
Foldy Lajos
Messages: 268 Registered: October 2001
|
Senior Member |
|
|
On Fri, 18 Apr 2008, vino wrote:
> Hi!
> I was trying out the 'FIX' command and i couldnt understand all the
> arguments present. Can someone help me please? below is whats i did!
> IDL> c=[1.2,-3.4,5.]
> IDL> print,fix(c)
> 1 -3 5
You have converted a float array to int.
FIX converts to IDL int, which is 16 bits wide, is signed and its range is
-32768 <= int <= 32767. I assume you know how numbers are represented in
computers. (The following is valid on little-endian machines only.)
Your float array occupies 12 bytes in memory, namely:
154 153 153 63 154 153 89 192 0 0 160 64 (in decimal)
> IDL> print,fix(c,0)
> -26214
reads memory as int from offset 0: the two bytes 154, 153 give -26214
(154+256*153 = 39322 = 65536-26214 = -26214)
> IDL> print,fix(c,1)
> -26215
reads memory as int from offset 1: the two bytes 153, 153 give -26215
(153+256*153 = 39321 = 65536-26215 = -26215)
> IDL> print,fix(c,2)
> 16281
reads memory as int from offset 2: the two bytes 153, 63 give 16281
(153+256*63 = 16281)
> IDL> print,fix(c,0,1)
> -26214
same as first, reads 1 int (from offset 0)
> IDL> print,fix(c,0,2)
> -26214 16281
>
same as first and third, reads 2 ints (from offset 0 and 2)
regards,
lajos
|
|
|