static int
bit_extract (bfd_byte *buffer, int offset, int count)
{
- int result;
- int bit;
+ unsigned int result;
+ unsigned int bit;
if (offset < 0 || count < 0)
return 0;
static int
bit_extract_simple (bfd_byte *buffer, int offset, int count)
{
- int result;
- int bit;
+ unsigned int result;
+ unsigned int bit;
if (offset < 0 || count < 0)
return 0;
}
static int
-sign_extend (int value, int bits)
+sign_extend (unsigned int value, unsigned int bits)
{
- value = value & ((1 << bits) - 1);
- return (value & (1 << (bits - 1))
- ? value | (~((1 << bits) - 1))
- : value);
+ unsigned int sign = 1u << (bits - 1);
+ return ((value & (sign + sign - 1)) ^ sign) - sign;
}
static void