In your sample code int is not doing anything. Indeed, if you actually run it with the strictures you show you will get the warning 'Useless use of int in void context at ...'.
Don't use &subName to call a sub. Use subName () instead. The &subName version of the call has some potentially nasty habits.
the following cleaned up sample may help:
use strict; use warnings; my @list; while (<DATA>) { chomp; push (@list, $_); } comp (); sub comp { printf "%-12s%-12s%-12s%-12s\n", (' +v', ' -v') x 2; foreach my $element (map int, @list) { my $negative = ~$element; printf "%11d %11d %#11.8b %#11.8b\n", $element, $negative, 0xFF & $element, 0xFF & $negative; } } __DATA__ 1 2 10 -1 -2 -10 123456 -123456 255 256
Prints:
+v -v +v -v 1 -2 0b00000001 0b11111110 2 -3 0b00000010 0b11111101 10 -11 0b00001010 0b11110101 -1 0 0b11111111 0b00000000 -2 1 0b11111110 0b00000001 -10 9 0b11110110 0b00001001 123456 -123457 0b01000000 0b10111111 -123456 123455 0b11000000 0b00111111 255 -256 0b11111111 0b00000000 256 -257 0b00000000 0b11111111
Note the use of map in the for loop to apply int to each of the array elements.
Update fixed stupid paste error (thanks toolic)!
In reply to Re: bit selections
by GrandFather
in thread bit selections
by biohisham
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |