On Tue, Sep 16, 2008 at 5:04 PM, John W. Krahn <[EMAIL PROTECTED]> wrote:

> Amit Saxena wrote:
>
>> Hi all,
>>
>
> Hello,
>
>  In the following code, the value of "$string" in last two cases is not
>> printed correctly.
>>
>> Please let me know what i am missing over here.
>>
>> *# cat l3.pl*
>> #! /usr/bin/perl
>>
>>
>>    $ONE_BYTE_RANGE     = 256;
>>
>
> A one byte range is 0 to 255 so 256 is 1 bit more than one byte.
>
>     $TWO_BYTE_RANGE     = 65536;
>>
>
> Same here, you are one bit over the two byte range.
>
>     $THREE_BYTE_RANGE   = 4294967296;
>>    $THREE_BYTE_RANGE_1   = 4294967295;
>>
>
> A three byte range is 0 to 16777215.  What you have there is a _four_ byte
> range plus one.
>
> If you have a 32 bit computer then the largest integer that perl can use is
> 4294967295.
>
>     $string = sprintf( "%d, %d ", hex( "9A" ), $ONE_BYTE_RANGE );
>>    print (" String = $string \n ");
>>    $string = sprintf( "%d", hex( "9A" ) - $ONE_BYTE_RANGE );
>>    print (" String = $string \n ");
>>    $string = sprintf( "%d , %d", hex( "BB76" ), $TWO_BYTE_RANGE );
>>    print (" String = $string \n  ");
>>    $string = sprintf( "%d", hex( "BB76" ) - $TWO_BYTE_RANGE );
>>    print (" String = $string \n ");
>>    $string = sprintf( "%ld , %ld ", hex("98EAB"), $THREE_BYTE_RANGE );
>>    print (" String = $string \n ");
>>    $string = sprintf( "%ld", hex("98EAB") - $THREE_BYTE_RANGE ) ;
>>    print (" String = $string \n ");
>>    $string = sprintf( "%ld", (hex("98EAB") - $THREE_BYTE_RANGE_1 - 1) ) ;
>>    print (" String = $string \n ");
>>
>> *# perl l3.pl*
>>  String = 154, 256
>>  String = -102
>>  String = 47990 , 65536
>>   String = -17546
>>  String = 626347 , -1
>>  String = -2147483648
>>  String = -2147483648
>>
>
> What numbers did you expect would be printed?
>
>
>
> John
> --
> Perl isn't a toolbox, but a small machine shop where you
> can special-order certain sorts of tools at low cost and
> in short order.                            -- Larry Wall
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> http://learn.perl.org/
>
>
>
What my doubt is why the output of following two statements is same :-

   $string = sprintf( "%ld", hex("98EAB") - $THREE_BYTE_RANGE ) ;
   print (" String = $string \n ");
   $string = sprintf( "%ld", (hex("98EAB") - $THREE_BYTE_RANGE_1 - 1) ) ;
   print (" String = $string \n ");

That also raises another question, does the perl also has a concept of
signed integer representation like "C".

Regards,
Amit Saxena

Reply via email to