Quote:
>Hi,
> I had a hex variable of the value 10
> On negation of 10 I got F5 and not FE as one would expect
> When 10 was negated using ~$hexvalue, I got 4294967285
> which on converting to hex is FFFFFFF5.
> The correct value of negating 10 should be FFFFFFFE...
> The same when done for 04 gave the correct value of FFFFFFFB
> Same holds true for 01, 02, 08 etc.. But not for 10,20,40,80 etc..
>Please let me know what am I doing wrong here...
I suspect you are wanting some automagical conversion, as negating 0xA
(decimal 10) gives FFFFFFF5. You can use the hex function, or if the
values are literals at compile-time 0x as a prefix indicates to the
compiler that the following number is hexadecimal.
#!/usr/bin/perl
{
print "enter number: ";
$answer = <STDIN>;
last unless defined $answer;
$hex = hex $answer;
printf "%08X negated is %08X\n", $hex, ~$hex;
redo;
Quote:
}
__END__
seems to produce the answers you are after,
hope this helps,
Mike
--
The "usual disclaimers" apply. | Meiko
Mike Stok | 130C Baker Ave. Ext
Meiko tel: (508) 371 0088 x124 |