flamey has asked for the wisdom of the Perl Monks concerning the following question:
This is how I thought I can negate a number:
But in the document i'm reading, it says to negate the number, and the example says the result of negating 0x0007 is FFF8. I looked on the web, and found someone gave an example of negating a number (in another programming lang) by XOR-ing the number with 0xFF:$p = 7; $n = -$p; # or 0 - $p print $n; # -7 printf "%x", $n; # FFFFFFF9
So, im confused, what's right?$p = 7; $n = $p ^ 0xFFFF_FFFF; # im on 32-bit winxp system printf "%x", $n; # FFFFFFF8
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Negating a number
by almut (Canon) on Mar 04, 2009 at 17:49 UTC | |
Re: Negating a number
by Illuminatus (Curate) on Mar 04, 2009 at 17:24 UTC | |
by ramrod (Curate) on Mar 04, 2009 at 17:33 UTC | |
Re: Negating a number
by repellent (Priest) on Mar 04, 2009 at 17:50 UTC | |
Re: Negating a number
by holli (Abbot) on Mar 04, 2009 at 17:24 UTC | |
Re: Negating a number
by kennethk (Abbot) on Mar 04, 2009 at 17:29 UTC |
Back to
Seekers of Perl Wisdom