I'm trying to convert a bitstring to a signed 32 bit integer value. The bitstring is in big-endian. I can get this to work for unsigned values, I use:
sub bin2dec {
return unpack("N", pack("B32", substr("0" x 32 . shift, -32)));
}
But I can't get it to work signed values. "N" is unsigned by default and there is no signed equivalent. The closest alternative is "i", which I have tried, but gives a bogus number because it defaults to 64 bits for me. I also tried "l" but that seems to be giving something completely wrong; I think it might be expecting a different memory ordering... any ideas?