Wise Monks, I have just come across a problem which I could not solve for a while. Ad rem, here is the script:
perl -e '$a = 127; printf "original:%04x, bit-negative version:%04x\n", $a, ~$a;'which produces some output, i.e:
original:007f, bit-negative version:ffffff80However I would like to receive a bit different one:
original:007f, bit-negative version:ff80Having searched throughout the monastery, I have found a hint which lead me to write a better script hint:
perl -e '$a = 127; $b = pack S, ~$a; $b = unpack S, $b; printf "%X, %X\n", $b, ~$a;'My questions is if there is a more friendly way of casting/formatting numbers in Perl? Like (casting) I know from C.
In reply to Casting numbers by bfilipow
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |