1. Originally Posted by cpjust
Why would it be any different for signed numbers?
As was already stated, if 11111110 is -1 for a byte, this will be read as an even number.

It will work on signed numbers if 2's complement is used.

2. Originally Posted by cpjust
Why would it be any different for signed numbers?
If it's a ones complement, negative numbers will be "even when they are odd". Of course the machines that use ones complement also have a "negative zero" value, and I haven't ever worked on a machine with ones complement for negative numbers.

--
Mats

3. Seeing as bit 0 is the sign bit, perhaps the bit will be shifted to the 3rd position instead?
I don't know, but it sounds logical.

4. Originally Posted by Elysia
Seeing as bit 0 is the sign bit, perhaps the bit will be shifted to the 3rd position instead?
I don't know, but it sounds logical.
I'm confused again. I thought bit 31 (on a 4-byte integer) was usually the sign bit. And, why does that matter? And ... 3rd position? And ... shifting? Why are we shifting?

5. Originally Posted by Elysia
Seeing as bit 0 is the sign bit, perhaps the bit will be shifted to the 3rd position instead?
I don't know, but it sounds logical.
Huh? Bit zero isn't the sign bit in any type of integers that I'm aware of. Ones complement still use the top bit for sign, but it uses a direct "inverse" of the positive number, instead of "inverse+1" as two's complement use.

--
Mats

6. My bad. It's the last bit (31th for 4 bytes), not the first (bit 0).

7. Originally Posted by MacGyver
As was already stated, if 11111110 is -1 for a byte, this will be read as an even number.

It will work on signed numbers if 2's complement is used.
Oh crap, I think you're right. I don't know much about those 1's vs 2's complement numbers, but I've only worked on machines that use 11111111 as -1.
What platforms use the other complement for numbers?

8. Originally Posted by matsp
It works on all machines that use two's complement for negative numbers, but if your -1 value is 1111....1110 then the and with 1 will produce zero for -1, which is of course incorrect.
Yeah, things get more confusing with negative values. But even the mod operator '%' can be confusing when applied to negative quantities.