| Public Scratchpad | Download, Select Code To D/L |
/me sighs.
My company has an online form for ordering replacement cabinet keys. I put in the key number, and under quantity, I put 3. A week or so later, I received 1 key.
So I went back to the form and put in the key number, and quantity = 2.
I received 1 key.
So I went back again and put in quantity = 1.
I received 1.
$n>1 ? $n = $n-($n-1) : $n = 1;
A discussion on coverting a hex string to a signed int...
planetscape chuckles SirBones++
ChemBoy: when I do the same operation on x86, it comes out as you say. For
unsigned numbers there's a good shortcut for this problem but not for signed,
so you just insert reverse between the pack and the unpack.
ChemBoy: making the total line perl -le'$str = "0001";print unpack "s", reverse pack "H4",$str'
tye: that code depends on the endianness (in case that wasn't clear)
SirBones: Excellent! Works!
ChemBoy: sorry about the extra steps, I clearly need to recaffeinate
SirBones is near tears. It's sick how long I've spent on this bug.
ChemBoy: Yeah, if you ever distribute that code, you will probably want to do
a little check to make sure your byte-order is correct before you run that line.
Or I and the other SGI/Mac users of the world will hunt you down and smack you on
the big end. ;-)
planetscape offers up the gnawed bones of her victims if that would make SirBones
feel better...
SirBones appreciates the gesture, but is too tired to eat.
ChemBoy: That is to say: use Config; my $packed = pack "H4", $str;
if ('4321' eq $Config{byteorder}) { $packed = reverse $packed; }
print unpack "s", $packed;)
planetscape: maybe a wee hug would do instead... the dragon furls her wings
'round SirBones and gives a gentle squeeze...