I am using sprintf in Perl to convert decimal numbers to their hex equivalents, as in:
my $positive = sprintf("X'%02X'", 1); # X'01'
my $negative = sprintf("X'%02X'", -1); # X'FFFFFFFFFFFFFFFF'
Why does the negative number always get sign-extended to the 8-byte representation of the number, even if the precision specified in sprintf is smaller?
Is there a way to avoid this so I don't have to substring the value every time? The same result occurs even if I remove the 0, as in: sprintf("X'%2X'", -1).